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
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:
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)
> fromAmbList = M.fromListWith (++) . map (\(k,v) -> (k,[v]))
>
> fromAmbList :: Ord k => [(k, a)] -> Map k [a]
>