"do" notation and ">>"
Koen Claessen
koen@cs.chalmers.se
Sun, 14 Apr 2002 13:20:04 +0200 (MET DST)
| do {e ; stmts} = e >> do {stmts}
With the risk of being late at this, and with the risk of
repeating something that has already been said (because I
have been away), I will give my two euro-cents.
I remember a discussion at the Haskell mailing list about
the possibility of creating a nasty space leak with this
translation. After all, there is a difference between:
<e1> >> <e2>
which, for the default definition of >> expands to an
expression which is operationally equivalent to:
<e1> >>= let x = <e2> in \_ -> x,
and:
<e1> >>= \_ -> <e2>.
In the first case, x is shared between successive
invocations, but in the second case, e2 is recomputed.
I remember that the example involved a definition like:
f = do ...; print [1..]
In the translation in the report, the list [1..] is shared
between all invocations of f, whereas the current GHC
translation does not.
So, changing the translation in GHC might actually introduce
a very nasty space leak in existing programs!
/Koen.
--
Koen Claessen
http://www.cs.chalmers.se/~koen
Chalmers University, Gothenburg, Sweden.