[Haskell-beginners] a problem with maps

Dennis Raddle dennis.raddle at gmail.com
Sat Jul 23 15:17:33 CEST 2011


I understand your point, but the spirit of Haskell as I have encountered it
(as a beginner, reading Typeclasspedia and other sources) would be

- Of course you need to learn about arrows and applicative functors.You need
to do that anyway.

- The expression "map (second pure)" is simpler in the sense it has fewer
moving parts, and it's worth understanding how to read it and how to write
things like it

That's how I understand the spirit of Haskell, although I could have a
limited perspective.

Dennis


On Sat, Jul 23, 2011 at 5:44 AM, David Place <d at vidplace.com> wrote:

>
> On Jul 22, 2011, at 10:58 PM, Ertugrul Soeylemez wrote:
>
> >   fromAmbList :: Ord k => [(k, a)] -> Map k [a]
> >    fromAmbList = M.fromListWith (++) . map (second pure)
>
> If I am reading your code, I may look up second and find it in
> Control.Arrow.  I have to learn about Arrows to understand your code?  And
> pure makes me need to study the Applicative class.  I imagine that it is
> likely that second is the only thing from Control.Arrow that you are using
> and pure is the only thing from Control.Applicative.  So, you need two lines
> of extra code to express what could be expressed much more perspicuously
> as:
>
> >
> >   fromAmbList :: Ord k => [(k, a)] -> Map k [a]
> >    fromAmbList = M.fromListWith (++) . map (\(k,v) -> (k,[v]))
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110723/d6eabef5/attachment.htm>


More information about the Beginners mailing list