"interact" behaves oddly if used interactively

Olaf Chitil olaf at cs.york.ac.uk
Thu Oct 2 12:06:50 EDT 2003

Simon Marlow wrote:

> So, we're agreed that the presence of lazy evaluation makes implementing
> optimistic evaluation (and other evaluation strategies) more
> complicated.  Personally, I find it disturbing that the presence of this
> family of library functions affects something as low-level as the
> evaluation strategy of the language.  Or, to put it another way, it
> enforces a particular evaluation strategy on a part of the language,
> when the rest of Haskell makes no such restrictions.

Lazy IO doesn't make lazy evaluation more complicated ;-)
Optimistic evaluation is a already a complicated evaluation strategy and
in my opinion lazy IO just makes it a bit more complicated.
Lazy IO does not force you to use lazy evaluation any more than other
uses of non-strictness force optimistic evaluation to bail out of eager

> I would expect, in a pure language, that I could reduce any expression
> in a program to HNF (or _|_) without affecting the meaning of the
> program.  In Haskell, I can only do this so long as the expression
> doesn't involve any lazy I/O.

You always have to be careful with reducing an arbitrary expression in
case it is _|_.

> The real problem is that lazy I/O injects side effects into the pure
> world of expressions.  Haskell has a perfectly good system for
> encapsulating side effects - the IO monad.  So why put these sneaky side
> effects into pure values?

I fear one problem is that the word "side effect" is not properly

Actually both getContents and interact are in the IO monad. Since the
action "interact" is not terminated until the input stream ends, I do
not see any problem there. Evaluation never leaves the IO monad until
termination. getContents is more strange. However, you can just define
its semantics to yield a random string. When you are not careful you may
certainly get something nearly random ;-)

I completely agree with Thomas Hallgren's message. I also view the IO
monad as a temporary solution and regret that research into better lazy
IO seems to have stoped.


 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

More information about the Haskell-Cafe mailing list