[Haskell-cafe] Is hGetLine lazy like hGetContents? And what about this todo item?

Jason Dagit dagit at galois.com
Thu Mar 25 11:40:35 EDT 2010


I was trying to figure out if hGetLine is safe to use inside of
withFile.  Specifically, I want to return the line I read and use it
later, without inspecting it before withFile calls hClose.

If you want to understand the concern I have, look here:

There is a bit of explanation showing that hGetContents can be
problematic with withFile.

I can tell from reading the source of hGetContents that it uses
unsafeInterleaveIO so this make sense to me why that wiki page talks
about hGetContents:

When I read the source of hGetLine, it is less clear to me if I need to
be concerned.  I believe it is not lazy in the sense of lazy IO above.
Could someone else please comment?

Then I notice this 'todo' item in the description:
-- ToDo: the unbuffered case is wrong: it doesn't lock the handle for 
-- the duration.

The code itself looks to me like it only handles the buffered case.
Perhaps this todo is obsolete and needs to be removed?  If it's not
obsolete, do we need to create a ticket for this?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 1895 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100325/5b6b044e/smime.bin

More information about the Haskell-Cafe mailing list