[Haskell-cafe] Re: How do I get this done in constant mem?

Ben Franksen ben.franksen at online.de
Sun Oct 11 08:17:57 EDT 2009


mf-hcafe-15c311f0c at etc-network.de wrote:
> On Sat, Oct 10, 2009 at 11:11:24PM +0200, Daniel Fischer wrote:
>> No, readFile reads the file lazily.
> 
> hm?  oh, you are right, now that i fixed all the other problems in my
> code readFile isn't a problem any more either...  (-:
> 
> (but then how does it know when to close the handle?  gotta go read
> the code i guess.)

It is somewhat documented, see
http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html
or http://www.haskell.org/onlinelibrary/io.html, section 21.2.2 Semi-Closed
Handles:

"[...] A semi-closed handle becomes closed:
 * if hClose is applied to it; 
 * if an I/O error occurs when reading an item from the handle; 
 * or once the entire contents of the handle has been read."

It is not stated here that the file /immediately/ gets closed after the last
byte has been read. Does that mean implementations are free to postpone
closing (e.g. until the next GC cycle)?

Cheers
Ben



More information about the Haskell-Cafe mailing list