FixIO/ Tackling Awkward Squad

Levent Erkok
Fri, 16 Feb 2001 16:40:45 -0800

> Sorry, this one should be OK:
> fixIO m = let
>     x = unsafePerformIO (liftM Box (m (unbox x)))
>     in return . unbox $! x

Unfortunately, that's not good either: Consider again:

e :: IO Int
e = do { x <- fixIO (\x -> do {putStr "hello"; return (x+1)}); return 2} 

If I run e several times, I should see "hello" each time on my screen.
But that doesn't happen with this definition:

Main> e
Main> e
Main> e 

I see the effect only the first time I run it. But e has type IO Int,
hence each time I run it, I should see the string hello. If I use the
library version of fixIO (found in IOExts) or Simon PJ's version, hello
is printed each time e is run, which is the correct behavior.