Proposal: Add a few extra members to Foldable and Traversable classes

Edward Kmett ekmett at
Sun Sep 21 15:37:12 UTC 2014


I really do consider foldMap to be the canonical form, and both foldr and
foldl to be definable things in terms of it, but for historical reasons
foldMap has a default definition in terms of foldr.


On Sun, Sep 21, 2014 at 11:21 AM, Sjoerd Visscher <sjoerd at>

> foldMap is used to provide a 'natural' fold regardless of associativity.
> foldMap and foldr are are mutually definable, by using Endo to get foldr
> from foldMap, or just accepting a right associated monoidal reduction.
> This is why foldr or foldMap are the minimal definitions.
> However, you can't build foldr in terms of foldl with the right behavior
> on infinite containers, so foldl is _not_ a viable minimal definition for
> Foldable in a world where you can have infinitely big things to fold!
> Wouldn’t it be the other way around for infinite snoc-lists?
> Sjoerd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list