[Haskell-beginners] A first try

David Place d at vidplace.com
Mon Jun 27 13:58:03 CEST 2011


____________________
David Place   
Owner, Panpipes Ho! LLC
http://panpipesho.com
d at vidplace.com



On Jun 27, 2011, at 3:50 AM, Heinrich Apfelmus wrote:

> Good point, but this actually shows that  withFile  should be even lazier. In particular:
> 
> * The file should not be opened until the string is demanded.
> * The file should be closed as soon as the string has been demanded in full.

Suppose the file is only partially demanded as in the case I quoted earlier.

print10 = 
     do
       contents <- withFile "/usr/share/dict/words" ReadMode (\h -> hGetContents h)
       print $ take 10 contents

The file would never be closed.


More information about the Beginners mailing list