[Haskell] line-based interactive program

Olaf Chitil O.Chitil at kent.ac.uk
Fri Jul 8 13:21:54 EDT 2005

Andrew Pimlott wrote:

> It is one thing to embrace lazy evaluation order, and another to embrace
> lazy IO (implemented using unsafeInterleaveIO).  As a relative newcomer
> to Haskell, I got the impression that the "interact" style was always a
> hack, discarded for good reason in favor of the IO monad.  Is there a
> strong case for interact?
Why invent a new feature (IO monad) if you can do IO already based on 
lazy evaluation?

It is no argument against "interact" that all Haskell systems use 
unsafeInterleaveIO to implement it.  Any kind of IO needs some 
primitive, you could just as well have interact directly as primitive.

In fact, unsafeInterleaveIO shows up limitations of the IO monad. 
Without this strange primitive (what is actually unsafe about it?) you 
cannot simulate lazy IO within the IO monad. Another example is the 
previously discussed line buffering of input. If this were not a 
primitive in the IO monad, how would you define it in Haskell without 
some nasty hacks (a top-level IORef springs to my mind)?

The IO monad certainly has advantages with respect to modularity. A 
shame that you cannot freely mix lazy IO and monadic IO in a program. I 
find it sad that the IO monad has so widely been accepted that nobody 
seems to search for better alternatives any more.


More information about the Haskell mailing list