Open Gurkenglas opened 8 years ago
atomicModifyIORefM :: MonadIO m => IORef a -> (a -> m (b, a)) -> m b
This might be impossible even for atomicModifyIORefM :: IORef a -> (a -> IO (b, a)) -> IO b
, or at least it would require adding a new primop to GHC – but I'm not sure. Should ask someone on #ghc about that.
The IO action m (b, a)
could write to or read from the IORef, so it can't be atomic.
atomicModifyIORef :: IORef a -> (a -> (a, b)) -> IO b
intoatomicModifyIORefM :: MonadIO m => IORef a -> (a -> m (b, a)) -> m b
and similarly for nearby functions.runIORefStateT :: MonadIO m => IORef s -> StateT s m b -> m b
or perhaps flipped would put the full power ofControl.Monad.Trans.State
behind this.Not sure how to prefix this, when base should not have an mtl dependency... but at the very least,
IORef a -> (a -> IO (b, a)) -> IO b
is overdue.