aelve / haskell-issues

An unofficial issue tracker for all things Haskell-related
18 stars 0 forks source link

Add monadic IORef functions (e.g. atomicModifyIORefM) #6

Open Gurkenglas opened 8 years ago

Gurkenglas commented 8 years ago

atomicModifyIORef :: IORef a -> (a -> (a, b)) -> IO b into atomicModifyIORefM :: 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 of Control.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.

neongreen commented 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.

HuwCampbell commented 7 years ago

The IO action m (b, a) could write to or read from the IORef, so it can't be atomic.