
I don't really understand getContents. (Does anyone?) I have some code here (far too large to submit). If I do (on Linux, ghc4.08.1, both with and without optimisation) ------------------ contents <- hGetContents handle seq (last contents) (hClose handle) ------------------ the code works. However I looked at the manual and it seems that hClose should force the whole of contents to be read anyway. So I changed it to ------------------ contents <- hGetContents handle hClose handle ------------------ and then the code doesn't work. If these are meant to be the same, then we have a GHC bug. If not, could someone explain in words of one syllable why not? PS - if you want the source code you'll have to download and compile the whole of UniForM!!

contents <- hGetContents handle seq (last contents) (hClose handle)
vs.
contents <- hGetContents handle hClose handle
However I looked at the manual and it seems that hClose should force the whole of contents to be read anyway.
If some manual says this, it is wrong. The Haskell Report says that 'hGetContents' gives the handle a special status, called "semi-closed". A semi-closed handle becomes fully closed when 'hClose' is applied to it. When this occurs, the contents of the associated stream of characters (i.e. those returned by 'hGetContents') is truncated, and is the list of characters that have already been read from that handle. Regards, Malcolm
participants (2)
-
George Russell
-
Malcolm Wallace