Proposal: Foldable typeclass: make foldl' and foldr' class methods

Johan Tibell johan.tibell at
Mon Jun 20 22:44:41 CEST 2011

On Mon, Jun 20, 2011 at 10:11 PM, Duncan Coutts
<duncan.coutts at> wrote:
> Mm, the '1' variants are obvious. The fold and foldMap are more
> interesting. I'd have to think harder about what their default
> definition would be, or what specialised implementations might look like
> (e.g. tree folds starting from the leaves and working towards the root).
> Are there any obvious use cases for strict monoid folds?

How about parallel folds? Here's something I'd like to support for HashMap:

    parFold :: Monoid m => (v -> m) -> HashMap k v -> m
    sumValues = parFold Sum

Another really nice property of monoid folds is that they get
call-site specialized automatically by GHC.


More information about the Libraries mailing list