[Haskell-cafe] readFile and closing a file

Mitchell, Neil neil.mitchell.2 at credit-suisse.com
Wed Sep 17 08:06:25 EDT 2008


Hi Henning,

I tend to use openFile, hGetContents, hClose - your initial readFile
like call should be openFile/hGetContents, which gives you a lazy
stream, and on a parse error call hClose.

Thanks

Neil

> -----Original Message-----
> From: haskell-cafe-bounces at haskell.org 
> [mailto:haskell-cafe-bounces at haskell.org] On Behalf Of 
> Henning Thielemann
> Sent: 17 September 2008 12:31 pm
> To: Haskell Cafe
> Subject: [Haskell-cafe] readFile and closing a file
> 
> 
> 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)?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 

==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================



More information about the Haskell-Cafe mailing list