Is there a parFoldMap? How about libraries for similar functions?

This is cute:

    foldPar [x] = x
    foldPar xs@(_:_:_) = foldPar
        $ foldr go [] (chunksOfTwo xs)
      where
        go a cont = par cont res `pseq` res : cont
          where
            res = uncurry (<>) a
    foldPar [] = mempty

where chunksOfTwo is an internal function marked {-# INLINEABLE chunksOfTwo #-} that groups every two elements in a list as either (a,b) or (a,mempty).

List fusion pushed this from 40-80 seconds on 100m list size to 7 seconds, which is still slower than a normal mconcat, but hey, spark overhead and Amdahl’s Law!

Now, I still need to figure out how to, first, deseq this so I get the intended “every element in the list is computed separately” as the pseq is blocking this behavior, and second, figure out how to directly use rewrite rules to implement this.

:smug: