"interact" behaves oddly if used interactively
olaf at cs.york.ac.uk
Wed Oct 1 15:29:08 EDT 2003
Simon Marlow wrote:
> Malcolm Wallace writes:
> > But the whole purpose of 'interact' is to use its argument as the
> > demanding function which drives lazy consumption of the input. It is
> > *designed* to reveal the evaluation behaviour, by hoisting it into
> > the I/O monad.
> This is why interact is bad, IMO: it forces you to think about the
> evaluation order. The evaluation order for Haskell is not part of the
> language definition - it is normally up to the implementation to pick a
> Except when you get to lazy I/O. The commonly accepted meaning for the
> lazy I/O operations forces the implementation to adopt a lazy evaluation
> strategy for values which require lazy I/O. For example, eager
> evaluation would be a completely valid implementation strategy for
> Haskell if it were not for lazy I/O.
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.
That is fine and should work well with 'interact', otherwise there is
something wrong with optimistic evaluation. Certainly pure eager
evaluation is not a valid evaluation strategy for Haskell.
Dept. of Computer Science, The University of York, York YO10 5DD, UK.
Tel: +44 1904 434756; Fax: +44 1904 432767
More information about the Haskell