Skip to content

RULES defined from TemplateHaskell get rejected by ghc

To repro in HEAD:

ghci> {-# RULES "" forall a b c. a * c + b * c = (a + b) * c #-} -- ok

ghci> :{
ghci| f x = x
ghci| $( [d| {-# RULES "" forall a b c. a * c + b * c = (a + b) * c #-} |] ) -- fail
ghci| :}

<interactive>:13:2: error:
    Rule "":
      Illegal expression: ((a_a2ft * c_a2fv) + (b_a2fu * c_a2fv))
      in left-hand side: ((a_a2ft * c_a2fv) + (b_a2fu * c_a2fv))
    LHS must be of form (f e1 .. en) where f is not forall'd

This is due to extra parens may be added by TemplateHaskell, this used to be even worse that followings would be rejected as well:

$( [d| {-# RULES "." forall a b. (.) a b foo = a (b foo) #-} |] )
$( [d| {-# RULES "foo" forall a b. foo a b = a b #-} |] )

but have been mitigated by 30e625e6

We may just be more flexible when validating the LHS as we compile to the same CoreExpr after removing the parens.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information