Re: [Haskell-cafe] Strange behaviour with writeFile

2007-02-04 Thread Donald Bruce Stewart
cmb21: > fo/haskell-cafe>, > > Errors-To: [EMAIL PROTECTED] > Status: O > Content-Length: 778 > Lines: 27 > > Hi, > > I am observing some rather strange behaviour with writeFile. > > Say I have the following code: > > answer <- AbstractIO.readFile "filename" > l

Re: [Haskell-cafe] Strange behaviour with writeFile

2007-02-04 Thread Udo Stenzel
C.M.Brown wrote: > I've found that: > > let (answer2, remainder) = parseAnswer (force answer) > > where > > force :: Eq a => a -> a > force x = if x==x then x else x > > Seems to do the trick. ...but I'd advise against using it. If the power fails at the right time, you're left with no file

Re: [Haskell-cafe] Strange behaviour with writeFile

2007-02-04 Thread C.M.Brown
Hi Neil, > When you add that extra line the act of writing out the remainer > causes the rest of the input to be fully evaluated and hence the > filehandle is closed. Ah, yes of course :) I've found that: let (answer2, remainder) = parseAnswer (force answer) where force :: Eq a => a -> a for

Re: [Haskell-cafe] Strange behaviour with writeFile

2007-02-04 Thread Neil Davies
Its about the lazyness of reading the file. The handles on the file associated (underlying readFile) is still open - hence the resource being in use. When you add that extra line the act of writing out the remainer causes the rest of the input to be fully evaluated and hence the filehandle is clo

[Haskell-cafe] Strange behaviour with writeFile

2007-02-04 Thread C.M.Brown
Hi, 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.putS