5

Is there any way to browse or search rewrite rules? When I use flags like -ddump-rule-firings or -ddump-rule-rewrites I just get the name of the rule that fired and the rewrite that it caused, but not the actual rule itself...

Ideally I'd like to see what rewrite rules are in scope via GHCi, but realistically I'd be willing to settle for just an exhaustive list of the rewrite rules present in base.

Alec
  • 31,829
  • 7
  • 67
  • 114
  • 1
    I would just grep for them. They start with `{-# RULES`. Unfortunately they're not first class citizens. – pdexter Jul 29 '16 at 07:19
  • @pdexter This is exactly the answer I was hoping NOT to get. xD – Alec Jul 29 '16 at 07:23
  • 1
    :D Take a read of this [http://www.yesodweb.com/blog/2016/02/first-class-stream-fusion](http://www.yesodweb.com/blog/2016/02/first-class-stream-fusion) – pdexter Jul 29 '16 at 07:26
  • 1
    This is a valid request. And it should at least be simple to query GHCi for all rules with a certain constant as the outmost symbol on the LHS (as rules are tacked to them). I recommend you open a feature request for it. This would be a nice task for a beginner contributor to GHC! – Joachim Breitner Jul 29 '16 at 09:14
  • 2
    @JoachimBreitner If no one has a good answer to this, I will go ahead and do that - might even try implementing it if it gets accepted (I've been looking for a good place to start hacking on GHC for ages)! – Alec Jul 29 '16 at 13:54
  • 1
    I don't think there's any other at the moment. You could use `haskell-src-exts` to parse all the `RULE` pragmas but it just might be an overkill for what you want now. – aesadde Jul 31 '16 at 11:06

1 Answers1

4

Alright, still hoping for a good answer to this, but if there isn't, I went ahead and did what pdexter suggested and grep'd base for rules. Here are the rules in base 4.9.


For anyone interested in replicating this:

  • clone http://git.haskell.org/ghc.git
  • navigate to ghc/libraries/base
  • grep recursively pcregrep -Mr '\{-# RULES(.|\n)*?#-\}' .
Alec
  • 31,829
  • 7
  • 67
  • 114