[Haskell-beginners] A first try

Yitzchak Gale gale at sefer.org
Mon Jun 27 19:45:08 CEST 2011


David Place wrote:
>>> 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.

I wrote:
>> I tried it - it does close the file.

> II'm not sure what you mean.  Did you create a new version of withFile that behaves
> as Heinrich suggested?  If so, please post its definition.

I just loaded Heinrich's withFile' in GHCi and ran it:

*WithFile> withFile' "/usr/share/dict/words" (print . take 10 . words)
open
["A","A's","AOL","AOL's","Aachen","Aachen's","Aaliyah","Aaliyah's","Aaron","Aaron's"]
close



More information about the Beginners mailing list