IO monad and lazy evaluation

Ketil Z. Malde ketil@ii.uib.no
23 May 2003 09:30:08 +0200


Glynn Clements <glynn.clements@virgin.net> writes:

> 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

Is too!

IMHO, the difference is that the program doesn't get the handle to
mess with, so there's no chance of doing something unexpected (like
closing it before all required input is read).

You still risk somebody messing with the file behind your back, but I
don't see how strictness changes that.

-kzm
-- 
If I haven't seen further, it is by standing in the footprints of giants