[Haskell] the wonders of lazy IO

Simon Marlow simonmar at microsoft.com
Wed Apr 20 05:58:58 EDT 2005


On 19 April 2005 06:30, Johannes Waldmann wrote:

> Thanks for the comments. Indeed I knew the solution -
> once I isolated the problem.
> 
> Note that ghc(i) behaves differently when running main2 below
> (it says "file is locked"). (hugs does not complain.)
> 
> import System
> 
> main1 = do
>      system "echo A > foo"
>      a <- readFile "foo"
>      system "echo B > foo"
>      b <- readFile "foo"
>      print (a == b)
> 
> main2 = do
>      writeFile "foo" "A"
>      a <- readFile "foo"
>      writeFile "foo" "B"
>      b <- readFile "foo"
>      print (a == b)

GHC is correct to complain about main2, FWIW.  The Haskell report
specifies single-writer/multiple-reader locking on files.

Cheers,
	Simon


More information about the Haskell mailing list