> (moderator, can you please include this mail at the bottom of my 
> previous mail?)
> 
> PS: I think the next example shows pretty well what goes wrong when 
> you're not closing the read-handle:
> 
> -------
> test = do writeFile' "123.txt" "blaat"
> 
>      appendFile' "123.txt" " 1"
>      z <- readFile' "123.txt"
> 
>      appendFile' "123.txt" " 2"
>      s <- readFile' "123.txt"
>          appendFile' "123.txt" " 3"
>      t <- readFile' "123.txt"
>          putStr ("\n\n")
>      putStr (z ++ "\n" ++ s ++ "\n" ++ t)
> 
> -------
> 
> Instead of "blaat 1
>                 blaat 1 2
>                  blaat 1 2 3"
> 
> three lines of "blaat 1 2 3" are outputted.

Note that on a conforming Haskell 98 system, the above program (with the
primes deleted) will fail.  For example, GHC responds:

Fail: resource busy
Action: openFile
Reason: file is locked
File: 123.txt

This is because Haskell 98 specifies that the IO system should implement
multiple-reader/single-writer locks on a per-file basis.

Cheers,
        Simon

_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to