"interact" behaves oddly if used interactively

Simon Marlow simonmar at microsoft.com
Wed Oct 1 15:52:43 EDT 2003


 
> Pardon? Haskell is a non-strict language. Using 'interact' is one of
> numerous situations where one takes advantage of non-strict semantics.
> (Keith just gave a different example.)
>
> Non-strict semantics does not prescribe the evaluation order, although
> usually lazy evaluation is used. I suppose you are talking about
> optimistic evaluation, which is a mixture of eager and lazy 
> evaluation.

Yes sorry, I meant optimistic evaluation.

> That is fine and should work well with 'interact', otherwise there is
> something wrong with optimistic evaluation.

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.

Cheers,
	Simon



More information about the Haskell mailing list