For example with lists, if I write a rule with the LHS of myFn [x]
, will it also be able to fire when the programmer writes myFn (x:[])
? or will I have to write a separate rule for every possible syntax?
Re-write rules get de-sugared. So a re-write rule like
{-# RULES
"myFn/singleton" forall x. myFn [x] = myOtherFn x
#-}
will be stored internally as
forall x. myFn (x:[]) = myOtherFn x
It's then applied to the de-sugared form of the program. (All optimization in GHC occurs on the de-sugared form of the program).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With