GHC’s rewrite rules enable programmers to write local program transformation rules for their own functions. The most notable use case are fusion optimizations, which merge multiple traversals of a data structure into one and avoids allocation of intermediate structures. However, GHC’s rewrite rules were too limited to express a rewrite rule that is necessary for proper fusion of the concatMap
function in a variant of fusion called stream fusion.
We introduce higher order patterns as a simple extension of GHC’s rewrite rules. Higher order patterns substantially broaden the expressiveness of rewrite rules that involve local variables. In particular they enable the rewriting of concatMap
such that it can be properly optimized. We implement a stream fusion framework to replace the existing fusion framework in GHC and evaluate it on GHC’s benchmark suite. Our stream fusion framework with higher order patterns show an average speedup of 7% compared to our stream fusion framework without it. However, our stream fusion framework is not yet able to match the performance of GHC’s existing fusion framework.
Additionally, we show that our higher order patterns can be used to simplify a GHC’s existing mechanism for rolling back failed attempts at fusion and at the same time solve a problem which prevented proper optimization in one example program. However, evaluating it on GHC’s benchmark suite shows a small regression in performance overall.
preprint (document.pdf) | 571KiB |
Sat 7 SepDisplayed time zone: Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna change
09:00 - 10:30 | |||
09:00 30mTalk | MicroHs - A Small Compiler for Haskell Haskell Lennart Augustsson Epic Games | ||
09:30 30mTalk | Higher Order Patterns for Rewrite Rules Haskell Jaro Reinders Delft University of Technology DOI File Attached | ||
10:00 30mTalk | Welcome to the Parti(tioning) (Functional Pearl) Haskell |