[Haskell-cafe] Re: Left fold enumerator - a real pearl overlooked?
Bayley, Alistair
Alistair.Bayley at invesco.com
Mon Mar 2 07:50:52 EST 2009
> From: haskell-cafe-bounces at haskell.org
> [mailto:haskell-cafe-bounces at haskell.org] On Behalf Of Duncan Coutts
>
> This can still be done using withFile and hGetContents. You
> just have to
> put the consumer inside the scope of withFile. The consumer
> can work in
> a streaming fashion. With lazy bytestrings this can be both efficient,
> work in constant memory and guarantee the file is closed.
>
> We guarantee the file is closed by using withFile. The only thing to
> watch out for is a consumer that doesn't consume as much as you were
> expecting before the file does get closed. You should notice
> that pretty
> quickly though since it should happen every time (whereas
> resource leaks
> are not so immediately visible).
Sure. But this case is the one that typically causes problems for beginners, who have not yet had the educating experience of being bitten by lazy IO. The standard café response to "why do I get <handle closed>" errors here?" is "you're using hGetContents and you haven't forced/consumed all of your file".
Alistair
*****************************************************************
Confidentiality Note: The information contained in this message,
and any attachments, may contain confidential and/or privileged
material. It is intended solely for the person(s) or entity to
which it is addressed. Any review, retransmission, dissemination,
or taking of any action in reliance upon this information by
persons or entities other than the intended recipient(s) is
prohibited. If you received this in error, please contact the
sender and delete the material from any computer.
*****************************************************************
More information about the Haskell-Cafe
mailing list