I have naive questions on `rules'.

1. 
In the program   data D a = D a Bool
                 fromD1 (D a _) = a

may the rule   forall x. fromD1 (D x _) = x

help the performance in the further program?
Instead, does the inlining (and simplifier?) do all the business?

2.
It may occur that GHC simplifies   nn x = not (not x)   :: Bool
to                                 nn   = id
- does it?
It may occur due to that Bool consists of only two values, and it is 
easy to find   not .not === id

Do it make sense  {-# RULES ... forall x. tail (x:xs) = xs,
                                          tail .(x:)  = id,  #-}
and the like?

3.
Has the compiler to simplify   map not (map not xs)   to  id   ?

It makes first          map (\x-> not (not x)) xs

according to the standard "mapmap" `rule'. 
Then,                   map (\x->x) xs,   map id xs

- according to its "not-not" knowledge (or maybe, rule).
Then, could the compiler guess also of 
                        map id xs === xs  ?

It looks like some sort of inductive reasoning needed.
Or maybe, the standard rule for this.
Suppose we have this rule. If, for example, the user puts
         {-# RULES "fg" forall x. f (g x) = x #-}

for some known to the user operators f,g,
then the rules would simplify  map f (map g xs) === xs   
automatically.

4.
Even without rules, has the compiler to simplify, say,
  reverse [x,y,z]   to   [z,y,x]  ?

Being applied recursively, `reverse' is not in-lined. But maybe, there
is an option in compiler for trying to compute each function partially 
by applying number N of reductions at compile time?
( -fevaluatePartiallyToDepth<NN>  :-) )

Thank you in advance for the comments.


------------------
Sergey Mechveliani
[EMAIL PROTECTED]





Reply via email to