On Tue, Aug 26, 2008 at 3:15 AM, Ashley Yakeley <[EMAIL PROTECTED]> wrote: > Judah Jacobson wrote: >> >> I've been wondering: is there any benefit to having top-level ACIO'd >> <- instead of just using runOnce (or perhaps "oneshot") as the >> primitive for everything? > > I don't think oneshots are very good for open witness declarations (such as > the open exceptions I mentioned originally), since there are pure functions > that do useful things with them.
I think you're saying that you want to write "w <- newIOWitness" at the top level, so that w can then be referenced in a pure function. Fair enough. But newIOWitness's implementation requires writeIORef (or an equivalent), which is not ACIO, right? I suppose you could call unsafeIOToACIO, but if that function is used often it seems to defeat the purpose of defining an ACIO monad in the first place. > Not sure about TVars either, which operate in the STM monad. Would you also > need a oneshotSTM (or a class)? Interesting point; I think you can work around it, but it does make the code a little more complicated. For example: oneshot uniqueVar :: IO (TVar Integer) uniqueVar =< atomically $ newTVar 0 -- alternately, use newTVarIO uniqueIntSTM :: IO (STM Integer) uniqueIntSTM = uniqueVar >>= \v -> return $ do n <- readTVar v writeTVar v (n+1) return n getUniqueInt :: IO Integer getUniqueInt = uniqueIntSTM >>= atomically -Judah _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe