Koen wrote:

>  |     Is it possible to write a monad such that this equality holds
>  |     both denotationally and operationally
>  | 
>  |       do {x <- foo; return x} = foo
>  | 
>  |     For all I know, the answer to this question is 
>  |     "yes, with sufficient sneakiness".

> Aha! Show us how!!

We tried the two example programs which started this dicussion on a tracer
that Alastair Penney has been developing in Bristol.  As far as we can see,
the problem boils down to a classic known problem: that if you have

   let (x,y) = e in ...

and you compile it naively, and x is evaluated and discarded, then y still
hangs on to (fst e) even though it is no longer needed.  We are not entirely
sure that this is the only problem, but it is clearly one of them.

It also seems to be fairly widely known that this problem cannot, in general,
be eliminated by a source-to-source transformation.

I know of two solutions for handling it.  One is for the compiler to generate
special code for "let (x,y) = e in ..." where the code for evaluating e also
updates x and y appropriately.  The other is for the run time system to look
for opportunities for eliminating indirection-like constructs such as "y = snd
(e1,e2)" either in the garbage collector or in a low-priority background
process.

Ian                        [EMAIL PROTECTED], http://www.cs.bris.ac.uk/~ian



Reply via email to