Does GHC simplify RULES?
Josef Svenningsson
josefs@cs.chalmers.se
Thu, 21 Feb 2002 16:24:04 +0100 (MET)
Hi!
A question about the RULES pragma.
Suppose I have the following RULES pragma:
{-# RULES
"foo" forall a . foo a = (\x -> bar x) a
#-}
Ok, it's stupid but I have examples where this is motivated, trust me.
Now, it seems that GHC simplifies the rule because what I get when
compiling it with -ddump-rules is the following rule:
"foo" __forall {@ t_a2UD a :: t_a2UD}
Test.foo @ t_a2UD a
= Test.bar @ t_a2UD a ;
It's \beta-reduced! Argh! Why is that?
So why is this a problem? Maybe I should give some explanation. The reason
is that I want to put a type signature on the (\x -> bar x) and make it
more general (i.e. forcing GHC to insert a type lambda after a lambda). I
then have other rules which match on higher ranked types. But in order for
these rules to apply the type lambda must be in the right place.
One other thing I tried in order to get the type lambdas on the right
place was to use rank 1 types (is that the correct name?):
xyzzy :: (a -> a) -> (forall b. b -> b)
but GHC simplified the type and just put the forall quantified (and hence
the type lambda) on the top level. Argh again!
Is there a way around this?
/Josef