[Haskell-cafe] readFile and closing a file
Henning Thielemann
lemming at henning-thielemann.de
Thu Sep 18 11:38:51 EDT 2008
On Wed, 17 Sep 2008, Mitchell, Neil wrote:
> 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.
Yes, this seems to be the right way. This weakness should be mentioned in
the docs of readFile. In production code, you cannot rely on a garbage
collector to close the file, because you might want to open a file for
writing after you have processed it with readFile, and there is warranty
that the file is already closed then.
More information about the Haskell-Cafe
mailing list