[Haskell-cafe] Strange behaviour with writeFile

C.M.Brown cmb21 at kent.ac.uk
Sun Feb 4 10:55:38 EST 2007


I am observing some rather strange behaviour with writeFile.

Say I have the following code:

answer <- AbstractIO.readFile "filename"
let (answer2, remainder) = parseAnswer answer
if remainder == "" && answer2 == ""
  then do
    AbstractIO.putStrLn $ "completed"
  else do
    AbstractIO.putStrLn answer2
    AbstractIO.writeFile "filename" remainder

With the above I get an error saying the resources to "filename" are
locked. If I add the line "AbstractIO.putStrLn $ show (answer2, remainder)
before I call writeFile it suddenly magically works!

Has anyone seen strange behaviour like this before?


More information about the Haskell-Cafe mailing list