Simon Marlow
Thu, 26 Oct 2000 04:13:58 -0700

> 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!!

Using hClose on a semi-closed handle is a Bad Thing.  The Haskell Report

	"Once a semi-closed handle becomes closed, the contents of 
	 the associated stream becomes fixed, and is the list of those
	 items which were succesfully read from that handle".

So I take this to mean that when you hClose a semi-closed handle, you get a
random amount of data in the handle which depends on how good your
compiler's strictness analyser is.  yesno?