[Haskell-cafe] readFile and closing a file

David Roundy droundy at darcs.net
Wed Sep 17 09:21:18 EDT 2008


On Wed, Sep 17, 2008 at 01:31:26PM +0200, Henning Thielemann wrote:
> Say I acquire a text by readFile, feed it to a lazy parser and the parser 
> stops reading because of a parse error. After the parser error I won't  
> fetch more characters from the text file, but readFile does not get to  
> know that and cannot close the file. Actually, when encountering a parser 
> error I could read the remaining characters from the file in order to let 
> readFile close the file eventually, but this sounds rather inefficient.  
> So, what is the right way to go, or do I have to stay away from readFile  
> (and maybe unsafeInterleaveIO at all)?

Eventually the garbage collector should close the file, I believe.

David


More information about the Haskell-Cafe mailing list