
On 11/2/07, Petr Hoffmann
wrote: import System.Cmd main = do System.Cmd.system "echo hello >output.txt" -- use the external application to create an output file o1 <- readFile "output.txt" System.Cmd.system "echo bye >output.txt" -- the second call to the external application o2 <- readFile "output.txt" putStr o1 -- "hello" expected, but "bye" printed return 0
Can you please give me some hint to solve this problem? I'm a beginning haskell developer and I'm still a bit confused by the IO monad.
I'm puzzled - when I run this on GHCi (v6.4, Windows XP) I get the following outcome *Main>main The process cannot access the file because it is being used by another process. hello *Main> This is certainly the behaviour I would expect - seeing "bye" being printed seems to me to be an error and may even constitute a violation of referential transparency. What implementation of GHC are you using ?
This looks like yet another case of the lazy-I/O goblins.
Yes, but not quite what everyone has being addressing.... -- -------------------------------------------------------------------- Andrew Butterfield Tel: +353-1-896-2517 Fax: +353-1-677-2204 Foundations and Methods Research Group Director. Course Director, B.A. (Mod.) in CS and ICT degrees, Year 4. Department of Computer Science, Room F.13, O'Reilly Institute, Trinity College, University of Dublin, Ireland. http://www.cs.tcd.ie/Andrew.Butterfield/ --------------------------------------------------------------------