---------- Forwarded message ---------- From: Alfredo Di Napoli <alfredo.dinap...@gmail.com> Date: 23 October 2012 10:35 Subject: Re: [Haskell-cafe] A clarification about what happens under the hood with foldMap To: Chaddaï Fouché <chaddai.fou...@gmail.com>
I'm sure I'm missing a point, but the "minimum" definition for a Foldable instance is given in terms of foldMap, so I get the cake for free, foldr included, right? In the example I have defined my treeSum as: treeSum = Data.Foldable.foldr (+) 0 So the only thing Haskell knows it that I want to fold over a Foldable for which foldMap (and therefore foldr) is defined, and specifically I want to fold using (+) as function. But foldMap is defined in terms of f, which in this case is Sum, because I want to sum things. It it were (*) f would have been Product, right? So what I'm missing is the relation between foldMap and foldr, aka "How Haskell infer from (+) that I want f = Sum and not something different"? I hope to have been clearer, don't know if I'm missing something crucial, though :) Thanks, A.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe