"interact" behaves oddly if used interactively

Robert Ennals Robert.Ennals at cl.cam.ac.uk
Wed Oct 1 15:59:33 EDT 2003


> No, optimistic evaluation does not work well with interact, because it
> causes the input stream to be evaluated (and therefore demanded) earlier
> than you would expect.  This is the problem: interact exposes more than
> just non-strictness, it exposes laziness.
> In Robert Ennals' implementation of optimistic evaluation he has to fall
> back to lazy evaluation for lazy I/O, precisely because of this problem.

Or to put it another way.

Optimistic Evaluation works fine with "interact". You can write programs that 
use interact, evaluate them optimistically, and they will behave exactly as 
they always did.

Optimistic Evaluation takes care to never speculatively evaluate anything that 
could have externally visible effects.

It is a guiding principle of Optimistic Evaluation that there should be no 
user-perceivable difference between optimistic evaluation and lazy evaluation.


More information about the Haskell mailing list