Well, not quite. ($!) (like `seq`, out of which it's built) forces evaluation only to "weak head normal form": essentially enough to determine the top-level constructor. Here, for String, that means only the first character need be evaluated, which in practice means only the first bufferful of the file is read. You need to use ($!!) or something like it to force evaluation of the entire file contents. [See http://www.mail-archive.com/haskell@haskell.org/msg15819.html.]
Dean
Ah, good point, I missed that.
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) -- -- Johannes Waldmann -- Tel/Fax (0341) 3076 6479/80 -- ---- http://www.imn.htwk-leipzig.de/~waldmann/ -------
participants (2)
-
Cale Gibbard -
Johannes Waldmann