
28 May
2011
28 May
'11
4:37 p.m.
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