Why does haskell require multiple rewrite rules depending on the function composition technique and length? Is there a way to avoid this?
For example, given the following code...
{-# RULES
"f/f" forall a. f ( f a ) = 4*a
#-}
f a = 2 * a
this works for
test1 = f ( f 1 )
however we need to add a rule for
test2 = f . f $ 1
and
test3 = f $ f 1
leaving us with the following rules
{-# RULES
"f/f1" forall a. f ( f a ) = 4 * a
"f/f2" forall a. f . f $ a = 4 * a
"f/f3" forall a. f $ f $ a = 4 * a
#-}
However, when we string these together or use some other forms of composition the rules do not fire.
test4 = f . f . f $ 1
test5 = f $ f $ f $ 1
test6 = f $ 1
Why is this? Do I have to write rewrite rules for every possible implementation?