Thu, 27 Apr 2000 19:20:57 +0200, Ralf Krueger <[EMAIL PROTECTED]> 
pisze:

>  main = do text <- readFile "xxx"
>            text' <- process $! text

$! will usually not suffice, because it forces only the beginning of
the list.

"foldr seq (return ()) text" should suffice.

Or use a GHC extension: IO.slurpFile.

IMHO lazy readFile, or possibly hGetContents only, should really be
improved to behave sanely when e.g. the file gets hClosed. Laziness
should not change any result except to turn some bottoms into other
values. This is about the only place in standard Haskell when laziness
can bite in some other way than causing poor performance.

Unless we are talking about unsafe extensions, which OTOH are very
useful too. Sometimes eliminating unsafePerformIO would require
huge rewrite of the whole program, making it less readable and less
efficient. But they should be clearly marked as unsafe. The safe
sublanguage should behave safely.

It is not obvious how to fix hGetContents. I might want to do one of
two things before closing the file:
- read the remaining part of the file now,
- discard the remaining part of the file,
and it could be bad to rely on the garbage collection to distinguish
between them (i.e. to determine whether the file contents will
be still needed).

-- 
 __("<    Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/
 \__/              GCS/M d- s+:-- a23 C+++$ UL++>++++$ P+++ L++>++++$ E-
  ^^                  W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK                  5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-


Reply via email to