Koen Claessen <[EMAIL PROTECTED]> wrote:
>   let x :: N Int
>       x = veryBigExpression
>  
>    in plus x x
> 
> Then "veryBigExpression" depending on an "Env" gets computed twice if you
> finally provide the "Env".

I do not see this as a problem.  In fact it forces you to think about
the difference between the computation and its value - one could imagine
that plus (or maybe not plus, but then some other operation) did not
treat its arguments in the same way, ie. it evaluates the two x'es in
different environments, and so you would expect the two different x'es
to behave differently.  In fact I find your suggestion by letting N be a
monad to be quite natural:  While the above piece of code evaluates
veryBigExpression twice in whatever silly environment plus might set up,
the following code evaluates veryBigExpression only once in the current
environment and adds the results:

  do x<-veryBigExpression
     plus (return x) (return x)

It is not that hard to read, I think.

Still you have a point:  If plus chooses to evaluate its arguments in
the same environment (as probably would be the case) you have no way to
exploit the sharing in the first example aboce, and you would end up
computing the same thing twice.

Michael Florentin Nielsen ([EMAIL PROTECTED])

Reply via email to