"do" notation and ">>"

Olaf Chitil olaf@cs.york.ac.uk
Wed, 24 Apr 2002 11:50:27 +0100

> I do not understand what full laziness has to do with all
> this! The big question is, in the following:
>   f = do <expr1>
>          <expr2>
> Should <expr2> be shared among different calls to f?  It is
> clear that <expr1> will, but <expr2> will not be shared,
> using the current translation used by GHC and Hugs.

Well, if a compiler implemented full lazyiness, then both translations
(with >>= and with >>) would share <expr2>...

I think that it is worth warning Haskell users about the potential space
leak you noticed, but I don't think that it should influence the
decision on "do" and ">>". I don't believe that it will break many
programs. How many programs produce large *input independent* output,
that is not already literally in the source, in a caf with a long

Unfortunately I'm not even sure that your warning should be added to the
Haskell report, because the report says hardly anything about sharing
and space usage. I believe even a call-by-name implementation or a full
laziness implementation would be fully Haskell 98 compliant. (I'm not
happy about that either).


 Dept. of Computer Science, The University of York, York YO10 5DD, UK. 
 URL: http://www.cs.york.ac.uk/~olaf/
 Tel: +44 1904 434756; Fax: +44 1904 432767