FixIO/ Tackling Awkward Squad

Simon Peyton-Jones simonpj@microsoft.com
Fri, 16 Feb 2001 04:14:26 -0800


| Dear Haskellers, 
|     After enjoying "Tackling the Awkward Squad" (Simon
| Peyton Jones), I wonder what other elements of the
| squad can be tackled in a simular way? Right now I am
| thinking about FixIO. This little bugger seems to show
| up in a lot of code! Can we give it an operational
| semantics a la Tackling the awkward squad? I am quite
| stumped on this one, so i wont event post my meager
| attempts, but rather hope someone brighter then me
| will :)  We need to add a new Value "FixIO N"... 

I'd be inclined to do it like this:

fixIO m = do { v <- newEmptyMVar
		 ; result <- m (unsafePerformIO (takeMVar v))
		 ; putMVar v result
		 ; return result }

Of course, this just begs the question of what exactly 
unsafePerformIO might mean, and we can only really answer that
when we give an operational semantics to the functional part
of the language as well as the imperative part.

But perhaps the meaning of fixIO becomes clearer with the above.
(Of course an implementation is free to implement it some other
way too.)

Simon