I wrote:
| > Note that the described behavior doesn't hold for _all_ monads. We can of
| > course take for the definition of W:
| >
| > type W = IO
| >
| > write = putStr
| >
| > And then (at least in Hugs) there is no space leak.
| > But this is not what you want, because now we are forced to have "foo"
| > only on toplevel...
Alastair answered:
| I just tried this on Hugs. I was expecting it to run out of stack space
| but, in fact, it runs out of heap space first. So your counterexample
| turns out to be an example :-)
Yes, you are right, it just takes a lot more time to run out of heapspace.
| On some systems such as GHC, I expect you'll run out of stack
| first, on Hugs you happen to run out of heap first.
Hm... GHC has very strange behavior. It runs out of space even in the
tail-recursive version!
| I can't think of any non-degenerate monad for which this program
| will run in constant space.
| [...]
| Standard results tell us that this is beyond a finite state machine (ie
| something that runs in constant space).
Good point.
| 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!!
Many attempts of my side failed, because it is very difficult not to
destroy laziness properties.
Thanks,
Koen.
--
Koen Claessen,
[EMAIL PROTECTED],
http://www.cs.chalmers.se/~koen,
Chalmers University of Technology.