FixIO/ Tackling Awkward Squad
Levent Erkok
erkok@cse.ogi.edu
Fri, 16 Feb 2001 10:49:14 -0800
Marcin 'Qrczak' Kowalczyk wrote:
>
> Fri, 16 Feb 2001 10:01:06 -0800, Levent Erkok <erkok@cse.ogi.edu> pisze:
>
> > The non-strict version is not good either, because it won't do
> > the effects!
>
> data Box a = Box {unbox :: a}
>
> fixIO m = let
> x = unsafePerformIO (liftM Box (m (unbox x)))
> in return (unbox $! x)
>
But that doesn't do the effects either..
I tried:
data Box a = Box {unbox :: a}
fixIOMQ :: (a -> IO a) -> IO a
fixIOMQ m = let x = unsafePerformIO (liftM Box (m (unbox x)))
in return (unbox $! x)
and:
do { x <- fixIOMQ (\x -> do {putStr "hello"; return (x+1)}); return
2}
Which did NOT print hello on the screen, before returning 2.
Maybe I'm missing your point?
By the way, the original version that Simon PJ wrote (with mvar's)
didn't have any of
these problems.
-Levent.