[Haskell-beginners] Data.Foldable/foldMap question
Patrick LeBoutillier
patrick.leboutillier at gmail.com
Sat May 28 22:37:45 CEST 2011
Hi,
I'm reading the LYAH book and on page 263 it says that if you define
Data.Foldable.foldMap you get Data.Foldable.foldl and
Data.Foldable.foldl for "free". The default implementation code of
Data.Foldable.foldr is:
foldr :: (a -> b -> b) -> b -> t a -> b
foldr f z t = appEndo (foldMap (Endo . f) t) z
I don't understand this code, but more specifically I don't get how
there can a Monoid constraint on foldMap's return type and not on
foldr/foldl.
Can any one explain what Endo is and how it works?
Thanks a lot,
Patrick
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
More information about the Beginners
mailing list