Difference between revisions of "GHC/Using Rule"

From HaskellWiki
Jump to: navigation, search
Line 1: Line 1:
== Using Rules in GHC ==
GHC's rewrite rules (invoked by the RULE pragma) offer a powerful way to optimise your program. This page is place for people who use rewrite rules to collect thoughts about how to use them.
If you aren't already familiar with RULES, read this stuff first:
* [http://www.haskell.org/ghc/docs/latest/html/users_guide/rewrite-rules.html The relevant section of the GHC user manual]
* [http://research.microsoft.com/%7Esimonpj/Papers/rules.htm Playing by the rules: rewriting as a practical optimisation technique in GHC]. This paper, from the 2001 Haskell workshop, describes the idea of rewrite rules.
=== Advice about using rewrite rules ===
* Remember to use the flag <tt>-fglasgow-exts</tt> and the optimisation flag <tt>-O</tt>
* Use the flag <tt>-ddump-simpl-stats</tt> to see how many rules actually fired.
* You need to be careful that your identifiers aren't inlined before your RULES have a chance to fire. To control this we add an <tt>INLINE [1]</tt> pragma to identifiers we want to match in rules, to ensure they haven't disappeared by the time the rule matching comes around.

Revision as of 11:41, 14 July 2006