[Haskell-beginners] a problem with maps

David Place d at vidplace.com
Sat Jul 23 14:44:56 CEST 2011


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]))
> 

____________________
David Place   
Owner, Panpipes Ho! LLC
http://panpipesho.com
d at vidplace.com






More information about the Beginners mailing list