On Thu, Jun 05, 2003 at 11:06:04AM +0100, Alastair Reid wrote:
That is, document unsafePerformIO enough to serve the FFI, but stipulate limits to preserve equational reasoning.
I think this is very hard to do.
When we use unsafePerformIO in the ffi, we are using the IO monad to sequence [un]marshalling side-effects. For example, peeking and poking foreign memory locations, allocating and freeing memory, etc. We might even be making remote procedure calls over a network (for example, COM could transparently do this) or creating a temporary file which is deleted after use.
These side effects might only affect this process (fiddling with memory) or they might affect the operating system (using sbrk to allocate more memory) or they might affect the network (remote procedure calls). They are certainly visible outside the confines of the Haskell code.
I don't propose to outlaw side-effects (there is language there that says they're hard to predict, and John suggests more), but to demand that the value returned is independent of the environment, which is needed for equational reasoning. I'm just talking about equations of values, not of values + side effects.