[Haskell-beginners] a problem with maps

Julian Porter julian.porter at porternet.org
Sat Jul 23 16:48:03 CEST 2011


Lifting to the List monad gives a very elegant solution:

listOutMap ::  k -> [a] -> [(k,a)]
listOutMap x ys = liftM2 (,) (return x) ys

Julian Porter
julian.porter at porternet.org
http://www.porternet.org


On 23 Jul 2011, at 15:08, Christian Maeder wrote:

> Am 23.07.2011 03:40, schrieb Dennis Raddle:
> ...
>> listOutMap :: Ord k => Map k [a] -> [(k,a)]
>> listOutMap m = concatMap (\(k,a) -> zip (repeat k) a) (M.toList m)
> ...
> 
> instead of "zip" and "repeat" I prefer just "map":
> 
>    "\ (k, as) -> map (\ a -> (k, a)) as"
> 
> (and don't bother to switch on TupleSections for "(k,)")
> 
> C.
> 
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110723/1524bc1e/attachment.htm>


More information about the Beginners mailing list