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

Duncan Coutts duncan.coutts at googlemail.com
Tue Jun 21 01:02:24 CEST 2011


On Mon, 2011-06-20 at 22:44 +0200, Johan Tibell wrote:
> On Mon, Jun 20, 2011 at 10:11 PM, Duncan Coutts
> <duncan.coutts at googlemail.com> 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

The strategies stuff uses Traversable I think.

To some degree I think you could do parallel evaluation with the
existing Foldable operations because you can pick the monoid, so you can
pick one that evaluates in parallel.

Needs a bit of thought and experimentation.

Duncan




More information about the Libraries mailing list