IO monad and lazy evaluation

Glynn Clements glynn.clements@virgin.net
Fri, 23 May 2003 19:14:42 +0100


Elke Kasimir wrote:

> > The problem isn't monads, or lazy functions, or even the interactions
> > between them. The problem is specifically lazy I/O, which is basically
> > a fudge which usually works in simple cases.
> > 
> > The "normal" (i.e. strict) I/O functions are perfectly safe.
> 
> Since Haskell is lazy by default, I consider lazy file reading to be
> the more natural choice, and also a safe one on operating systems
> like unix who lock a copy of the file at the time it's opened,

I'm not quite sure what you're saying here, but I think that you're
wrong. It appears that you are confusing Unix (which doesn't lock
files automatically) with Windows (which automatically locks a file
unless the program indicates that it allows concurrent access).

However, that isn't particularly relevant to the issue of lazy vs
strict I/O. Even if you use strict I/O, that doesn't eliminate the
problems associated with reading from a file which is being modified
concurrently. To handle that, you would need to use explicit locking
operations; even then, unless you use mandatory locking (which not all
Unices support), you are relying upon other programs honouring the
locks.

-- 
Glynn Clements <glynn.clements@virgin.net>