Hello!

[older mail]

On Sun, Feb 21, 1999 at 11:47:40PM -0800, Sigbjorn Finne (Intl Vendor) wrote:

> Sven Panne <[EMAIL PROTECTED]> writes: 

> ...
> >    * hClose on a semi-closed handle fails (4.02 has this bug, too):

> [...]

> But that's not the case here. By the time you get around to doing
> the 'hClose', you've read to the end of the file and the semi-closed
> handle has been closed for you (cf. report.)

That means if you have a program like this:

main = do
  h <- openFile ...
  c <- hGetContents h
  do_something c
  hClose h

You can't know whether the hClose is correct or not, except if it's
statically known whether do_something really uses up the whole 'c' or not.

To demonstrate that, I've written a long text file (in fact >1MB Postscript)
into /tmp/f.

Then, I ran this:

import IO

a1 c = putStr c

main = do
  h <- openFile "/tmp/f" ReadMode
  c <- hGetContents h
  a1 c
  hClose h

That gave the same failure:
Fail: illegal operation
Action: hClose
Handle: {closed}
Reason: handle is closed

Now, substitute this for a1:

a1 c = putStrLn $ (head . lines) c

and there's no failure.

If that is specified that way, I believe thats a mis-specification.

Regards, Hannah.

Reply via email to