[Haskell-cafe] [Q] A typing problem

Claus Reinke claus.reinke at talk21.com
Wed Apr 13 09:45:49 EDT 2005


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




More information about the Haskell-Cafe mailing list