[Haskell-cafe] parallel strategies for foldMap?

waldmann johannes.waldmann at htwk-leipzig.de
Tue Oct 10 16:39:51 UTC 2017

Dear Cafe,

I wonder if there is some accepted wisdom (and implementation)
to support parallel  foldMap  in some uniform way.

It should probably be tuneable for the case that mappend is
less or more expensive than the function to apply in the elements.

I can do the following, but it does not parallelize the mappends:

import qualified Data.Foldable as F
import Control.Parallel.Strategies

foldMapPar :: (Foldable f, Monoid b) => Int -> (a -> b) -> f a -> b
foldMapPar block f xs =
  F.fold ( map f (F.toList xs) `using` parBuffer block rseq )

In my application, the Foldable thingy is an unbalanced tree.

- J.W.

( the above is a genuine question, while the following
is a genuine announcement: don't miss the early registration
deadline for "Haskell in Leipzig" https://hal2017.softbase.org/ )

More information about the Haskell-Cafe mailing list