IO monad and lazy evaluation

Stefan Karrmann sk@mathematik.uni-ulm.de
Fri, 23 May 2003 23:23:29 +0200


Glynn Clements (Thu, May 22, 2003 at 08:11:02PM +0100):
> Graham Klyne wrote:
> 
> > Thanks for your comments.  (I had overlooked "readFile", which certainly 
> > looks safer.
> 
> It isn't:
> 
> readFile        :: FilePath -> IO String
> readFile name	=  openFile name ReadMode >>= hGetContents

Why does not hGetContents set a flag associated to the handle. The flag
is turned off if no lazy io thru the handle can happen. hClose checks
the flag and eventually passes the close to the OS if no flag is set
anymore.

Sincerly,
-- 
Stefan Karrmann

I like work; it fascinates me; I can sit and look at it for hours.