[Haskell-cafe] problem with IO, strictness, and "let"
andrewcoppin at btinternet.com
Fri Jul 13 14:59:22 EDT 2007
Stefan O'Rear wrote:
> The problem is that you're closing the file twice. When you call any
> function of the getContents family, you assign to that function the
> responsibility to close the file, no sooner than it is no longer needed.
> Don't call hClose yourself, Bad Things will happen.
Care to elaborate on "bad things"? (I.e., will this just crash the
program with an error, or will it do something more serious?) I must
admit, I thought closing such a file was simply no-op.
I can't remember why exactly, but somewhere or other I wrote some code
that does this. (Basically I want to shut the file without reading all
of it, so I can reopen it and start reading from the beginning again.)
Is there a sane way to do this? Or am I going to have to start playing
with explicit reads and writes? (Obviously I could just hang on to *all*
of the input stream returned from getContents - but that could be quite
large. The current way gives me low memory usage...)
More information about the Haskell-Cafe