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@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@haskell.org
http://www.haskell.org/mailman/listinfo/beginners