>>I'm trying to write a function that combines folding and mapping

a map is a fold:)

idList = foldr (:) []
map f = foldr ((:) . f) []

> foldmap :: (b -> b -> b) -> (a -> b) -> [a] -> b
> foldmap f m = foldr1 f . map m

alternatively, and dealing with empty lists as well

foldmap op n f = foldr (op . f) n

cheers,
claus


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to