Portability | portable |
---|---|

Stability | experimental |

Maintainer | bgwines@cs.stanford.edu |

Safe Haskell | Safe-Inferred |

Assorted types and typeclasses

# Documentation

`Zoldable`

is much like `Foldable`

, but with a crucial difference:

foldMap :: (Foldable t, Monoid m) => ( a -> m) -> t a -> m zoldMap :: (Zoldable t, Monoid m) => (t a -> m) -> t a -> m

It is an augmented form -- `foldMap f t`

is `zoldMap (f . g) t`

where `g :: t a -> a`

. With `foldMap`

, you lose information that you have at the time of invocation of `f`

: the `t a`

; the context in which the `a`

is enclosed is discarded. Consider the following situation: you have some tree type, e.g.

data Tree a = Leaf a | Node a (Tree a) (Tree a)

Suppose you want to get a list of all the nodes in the tree. This is just `zoldMap (x -> [x]) tree`

.