[Haskell-cafe] efficient combination of foldl' and foldr -> foldl'r

Henning Thielemann lemming at henning-thielemann.de
Fri Dec 5 17:43:10 EST 2008

On Fri, 5 Dec 2008, Ryan Ingram wrote:

> You're testing the interpreted code, so it's not surprising that the
> naive version performs better; the interpretive overhead only applies
> to your bit of glue code.

I wanted to avoid the optimizer to do clever things itself.

> Alternatively, at least compile the module with optimizations before
> running it in ghci:
> ryani$ ghc -ddump-simpl -O2 -c foldlr.hs >foldlr.core
> (This gives you "functional assembly language" to look at for
> examining code generation)
> ryani$ ghci foldlr.hs
> [...]
> Prelude FoldLR> :set +s
> Prelude FoldLR> test
> (1000000,'a')
> (0.39 secs, 70852332 bytes)
> Prelude FoldLR> testNaive
> (1000000,'a')
> (0.42 secs, 105383824 bytes)

There is still no clear advantage of foldl'r compared to foldl'rNaive, is 

More information about the Haskell-Cafe mailing list