Concerning the simplification rules,
J|rgen Gustavsson <[EMAIL PROTECTED]> writes on 7 Jun 1999
> There is another problem lurking here as well. Namely space issues.
> Consider the following program. It runs in constant space.
>
> let { xs = 1..n; x = head xs } in x - x + last xs + x
>
> Now transforming it using M - M -> 0 and 0 + M -> M yields
>
> let { xs = 1..n; x = head xs } in last xs + x
>
> which needs space proportional to n.
Indeed, it may occur that the compiler makes a more expensive code for
the latter function.
But on average, the simpler looking expressions would compute cheaper.
The simplifications like x - x --> 0 are somewhat orthogonal to the
subtle details of the head normal form implementation.
Probably, the compiler has to apply the rule simplifications and then
see what to do concerning these details - ?
As i understand this example, the interpreter cannot move the current
element of [1..n] to garbage because [1..n] is needed also for
(head [1..n]).
The compiler that understands rule application, kind of equational
reasoning, it has to be clever enough to optimize the above function
too.
In fact, some existing compilers do this, i tested.
------------------
Sergey Mechveliani
[EMAIL PROTECTED]