> As a simplified example of this, the following Haskell command
>
> do {s<- readFile "data"; writeFile "data" "123"; putStrLn s}
>
> always displays "123", rather than the original contents of the file.
>
> I think this is a bug? I/O commands should conceptually be done
> in the order that they appear in the 'do' sequence?
> If it is a bug, it exists in Hugs 1.3, Jan98 1.4, and June98 1.4.
The report seems to require this behavior. Here's the language in
section 7 (Basic Input/Output):
The @readFile@ function reads a file and
returns the contents of the file as a string. The file is read
lazily, on demand, as with @getContents@.
> My students have been writing a toy ATM request processing program
> that updates a list of bank accounts, stored in a file.
You could use this as an opportunity to teach about the necessity of
atomicity in updating a database.
mike