RE: updating file

2000-04-28 Thread Jan Skibinski
Erik: You have discovered the essence of monads, ie the difference between the bad and ugly world of side-effecting computations and the nice and clean world of pure functions. And even using my favourite example (*)! Let's put it in other words: I knew the difference,

Re: updating file

2000-04-28 Thread Jan Skibinski
On Fri, 28 Apr 2000, Fergus Henderson wrote: This is all fine and dandy if `currentSecond' is within `where' clause, because it will be always evaluated afresh. It might happen to work with current Haskell implementations, but I don't think there's any guarantee of that.

updating file

2000-04-27 Thread Jan Skibinski
Since we are in a mood for puzzles today .. How to update file "xxx" without making backup "yyy" first, as in: readFile "xxx" = writeFile "yyy" = readFile "yyy" = process =

Re: updating file

2000-04-27 Thread Ralf Krueger
On Thu, 27 Apr 2000 Jan Skibinski wrote: Since we are in a mood for puzzles today .. How to update file "xxx" without making backup "yyy" first, as in: readFile "xxx" = writeFile "yyy" = readFile "yyy" = process

Re: updating file

2000-04-27 Thread Sven Panne
Ralf Krueger wrote: I think, the problem can be solved by using the IO library and some strictness: import IO main = do text - readFile "xxx" text' - process $! text file - openFile "xxx" WriteMode hPutStr file text' hClose file seems

Re: updating file

2000-04-27 Thread Jan Skibinski
Ralf and Sven: Thank you both for your answers. I knew that strictness was needed here, but I was seeking some elegant solution. I prefer your answer, Sven, a bit more. Could you elaborate on your `hack' a bit more? It seems to be a good topic for

Re: updating file

2000-04-27 Thread Marcin 'Qrczak' Kowalczyk
Thu, 27 Apr 2000 19:20:57 +0200, Ralf Krueger [EMAIL PROTECTED] pisze: main = do text - readFile "xxx" text' - process $! text $! will usually not suffice, because it forces only the beginning of the list. "foldr seq (return ()) text" should suffice. Or use a GHC extension:

Re: updating file

2000-04-27 Thread Jan Skibinski
On 27 Apr 2000, Marcin 'Qrczak' Kowalczyk wrote: Unless we are talking about unsafe extensions, which OTOH are very useful too. Sometimes eliminating unsafePerformIO would require huge rewrite of the whole program, making it less readable and less efficient. But they should be clearly

Re: updating file

2000-04-27 Thread Fergus Henderson
On 27-Apr-2000, Jan Skibinski [EMAIL PROTECTED] wrote: currentSecond = second $ unsafePerformIO localDateTime where `localDateTime' has been defined via primitive call to C: localDateTime :: IO DateTime To my distress the clock stopped after the