Hi Cafe,
What this code does is straighforward. I was struck from the following sentences in LYAH:data Tree a = Empty | Node (Tree a) a (Tree a) deriving (Show, Eq)instance Foldable Tree wherefoldMap f Empty = memptyfoldMap f (Node l p r) = foldMap f l `mappend` f p `mappend` foldMap f rtreeSum :: Tree Int -> InttreeSum = Data.Foldable.foldr (+) 0
Notice that we didn't have to provide the function that takes a value and returns a monoid value.
We receive that function as a parameter to foldMap and all we have to decide is where to apply
that function and how to join up the resulting monoids from it.