[Haskell-beginners] problem with lazy IO
Dennis Raddle
dennis.raddle at gmail.com
Thu Nov 10 00:48:20 CET 2011
Hi Yitz,
I tried "evaluate" before posting my question, and for some reason it didn't
change the behavior. But strict bytestrings worked. I haven't tried Text
yet.
It was a pain putting "map (chr . fromIntegral)" in front of everything to
get
regular strings.
On Wed, Nov 9, 2011 at 10:40 AM, Yitzchak Gale <gale at sefer.org> wrote:
>
> To solve the problem when using readFile from the
> Prelude, you would need to make sure that each
> file is read all the way to the end as you go along.
> One trick sometimes used for that is to use the
> evaluate function from Control.Exception to force
> evaluation of the length of each file:
>
> b <- readFile s
> evaluate $ length b
> ...
>
> That would cause the entire contents of the file
> to be read into memory immediately and the
> file to be closed, like the behavior of readFile
> for strict ByteString and strict Text.
>
> -Yitz
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111109/102b54c4/attachment.htm>
More information about the Beginners
mailing list