I was wondering why, since IO is an instance of MonadFix [1], and therefore of ArrowLoop (Kleisli m), and since "The loop operator expresses computations in which an output value is fed back as input, even though the computation occurs only once." [2], the MonadFix or ArrowLoop class (through use of mfix or loop, respectively) doesn't appear in anyone's suggestion, where the top-level state was the thing looped over.

Or is this more or less what is going on in the function

oneShot :: IO a -> ACIO (IO a)
oneShot io = mdo mv <- newMVar $ do a <- io
                                    let loop = do putMVar mv loop
                                                  return a
                                    loop
                 return $ do act <- takeMVar mv
                             act

but without explicitly using the MonadFix or ArrowLoop classes?

Dan

[1] http://www.haskell.org/ghc/docs/6.4.1/html/libraries/base/Control-Monad-Fix.html [2] http://www.haskell.org/ghc/docs/6.4.1/html/libraries/base/Control-Arrow.html

Claus Reinke wrote:

what we do not know is how to share IO actions themselves in a
demand-driven way, ie how to describe an IO action that is executed at
most once, only on demand, with shared result.


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to