Data.Foldable causes missed foldr/build opportunities
Gabriel Gonzalez
gabriel439 at gmail.com
Thu Jul 25 19:22:50 CEST 2013
I'm now in favor of the `Data.Foldable` proposal, but I just wanted to
mention that the proposal needs to include some extra pragma work to
ensure that build/foldr optimizations fire. I was just experimenting
with the following combinator for `pipes` trying out the following two
versions:
each :: (Monad m) => [a] -> Producer a m ()
each = mapM yield
each :: (Monad m, Foldable f) => f a -> Producer a m ()
each = Data.Foldable.mapM yield
When I do a pure `pipes`-based fold over both `Producers`s, the version
specialized to lists triggers a firing of the build/foldr fusion rule
and runs about 20% faster. The true improvement for `mapM` by itself is
probably even greater than that because I haven't optimized the folding
code yet. The latter version does not trigger the rule firing. Either
way I'm going to include the latter `Foldable` version but I just wanted
to mention this because I remember people were asking if this would
impact fusion or not.
More information about the Libraries
mailing list