FW: lazy file reading in H98
Marcin 'Qrczak' Kowalczyk
9 Apr 2001 16:46:05 GMT
Sun, 08 Apr 2001 19:12:10 +0100, Olaf Chitil <firstname.lastname@example.org> pisze:
> So only if you continue evaluating `contents' after `hClose' *and*
> expect to get the full remaing file contents, then you have a problem.
Indeed. But in a lazy language it's not always obvious that the
evaluation of contents happens after hClose.
Another problem with readFile is that reading many files requires many
open file descriptors if their contents are not evaluated early enough.
This has bitten me in practice.
I agree that reading the rest on hClose would be dangerous, since
the programmer might be no longer interested in it. So perhaps an
explicit operation on a handle should be provided: similar to hClose,
but which causes any remaining contents of a semi-closed handle to be
slurped? Thus for files closed with that operation hGetContents could
be safely treated as if it was strict (assuming that file contents
don't change over time).
Applying 'foldr (const id) (return ())' to the contents string is
not perfect: unintuitive, requires to hold the contents string,
and probably not as efficient as possible.
__("< Marcin Kowalczyk * email@example.com http://qrczak.ids.net.pl/
^^ SYGNATURA ZASTĘPCZA