{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
module Control.Monad.Ref (
MonadRef(..),
MonadAtomicRef(..)
) where
import Control.Concurrent.STM (STM)
import Control.Concurrent.STM.TVar (TVar,
newTVar,
readTVar,
writeTVar)
import Control.Monad.ST (ST)
import Control.Monad.Trans.Cont (ContT)
#if !MIN_VERSION_transformers(0,6,0)
import Control.Monad.Trans.Error (ErrorT, Error)
#endif /* !MIN_VERSION_transformers(0,4,0) */
#if MIN_VERSION_transformers(0,4,0)
import Control.Monad.Trans.Except (ExceptT)
#endif /* MIN_VERSION_transformers(0,4,0) */
import Control.Monad.Trans.Identity (IdentityT)
#if !MIN_VERSION_transformers(0,6,0)
import Control.Monad.Trans.List (ListT)
#endif /* !MIN_VERSION_transformers(0,4,0) */
import Control.Monad.Trans.Maybe (MaybeT)
import Control.Monad.Trans.Reader (ReaderT)
import Control.Monad.Trans.State.Lazy as Lazy (StateT)
import Control.Monad.Trans.State.Strict as Strict (StateT)
import Control.Monad.Trans.Writer.Lazy as Lazy (WriterT)
import Control.Monad.Trans.Writer.Strict as Strict (WriterT)
import Control.Monad.Trans.Class (lift)
import Data.IORef (IORef,
#if MIN_VERSION_base(4,6,0)
atomicModifyIORef',
modifyIORef',
#endif /* MIN_VERSION_base(4,6,0) */
atomicModifyIORef,
modifyIORef,
newIORef,
readIORef,
writeIORef)
import Data.Monoid (Monoid)
import Data.STRef (STRef,
#if MIN_VERSION_base(4,6,0)
modifySTRef',
#endif /* MIN_VERSION_base(4,6,0) */
modifySTRef,
newSTRef,
readSTRef,
writeSTRef)
class (Monad m) => MonadRef m where
type Ref m :: * -> *
newRef :: a -> m (Ref m a)
readRef :: Ref m a -> m a
writeRef :: Ref m a -> a -> m ()
modifyRef :: Ref m a -> (a -> a) -> m ()
modifyRef Ref m a
r a -> a
f = Ref m a -> m a
forall a. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m a
r m a -> (a -> m ()) -> m ()
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ref m a -> a -> m ()
forall a. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
r (a -> m ()) -> (a -> a) -> a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
f
modifyRef' :: Ref m a -> (a -> a) -> m ()
modifyRef' Ref m a
r a -> a
f = Ref m a -> m a
forall a. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m a
r m a -> (a -> m ()) -> m ()
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
x -> let x' :: a
x' = a -> a
f a
x in a
x' a -> m () -> m ()
forall a b. a -> b -> b
`seq` Ref m a -> a -> m ()
forall a. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
r a
x'
class (MonadRef m) => MonadAtomicRef m where
atomicModifyRef :: Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef' :: Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef' Ref m a
r a -> (a, b)
f = do
b <- Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef Ref m a
r
(\a
x -> let (a
a, b
b) = a -> (a, b)
f a
x
in (a
a, a
a a -> b -> b
forall a b. a -> b -> b
`seq` b
b))
b `seq` return b
instance MonadRef (ST s) where
type Ref (ST s) = STRef s
newRef :: forall a. a -> ST s (Ref (ST s) a)
newRef = a -> ST s (STRef s a)
a -> ST s (Ref (ST s) a)
forall a s. a -> ST s (STRef s a)
newSTRef
readRef :: forall a. Ref (ST s) a -> ST s a
readRef = STRef s a -> ST s a
Ref (ST s) a -> ST s a
forall s a. STRef s a -> ST s a
readSTRef
writeRef :: forall a. Ref (ST s) a -> a -> ST s ()
writeRef = STRef s a -> a -> ST s ()
Ref (ST s) a -> a -> ST s ()
forall s a. STRef s a -> a -> ST s ()
writeSTRef
modifyRef :: forall a. Ref (ST s) a -> (a -> a) -> ST s ()
modifyRef = STRef s a -> (a -> a) -> ST s ()
Ref (ST s) a -> (a -> a) -> ST s ()
forall s a. STRef s a -> (a -> a) -> ST s ()
modifySTRef
#if MIN_VERSION_base(4,6,0)
modifyRef' :: forall a. Ref (ST s) a -> (a -> a) -> ST s ()
modifyRef' = STRef s a -> (a -> a) -> ST s ()
Ref (ST s) a -> (a -> a) -> ST s ()
forall s a. STRef s a -> (a -> a) -> ST s ()
modifySTRef'
#endif /* MIN_VERSION_base(4,6,0) */
instance MonadRef IO where
type Ref IO = IORef
newRef :: forall a. a -> IO (Ref IO a)
newRef = a -> IO (IORef a)
a -> IO (Ref IO a)
forall a. a -> IO (IORef a)
newIORef
readRef :: forall a. Ref IO a -> IO a
readRef = IORef a -> IO a
Ref IO a -> IO a
forall a. IORef a -> IO a
readIORef
writeRef :: forall a. Ref IO a -> a -> IO ()
writeRef = IORef a -> a -> IO ()
Ref IO a -> a -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef
modifyRef :: forall a. Ref IO a -> (a -> a) -> IO ()
modifyRef = IORef a -> (a -> a) -> IO ()
Ref IO a -> (a -> a) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef
#if MIN_VERSION_base(4,6,0)
modifyRef' :: forall a. Ref IO a -> (a -> a) -> IO ()
modifyRef' = IORef a -> (a -> a) -> IO ()
Ref IO a -> (a -> a) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef'
#endif /* MIN_VERSION_base(4,6,0) */
instance MonadRef STM where
type Ref STM = TVar
newRef :: forall a. a -> STM (Ref STM a)
newRef = a -> STM (TVar a)
a -> STM (Ref STM a)
forall a. a -> STM (TVar a)
newTVar
readRef :: forall a. Ref STM a -> STM a
readRef = TVar a -> STM a
Ref STM a -> STM a
forall a. TVar a -> STM a
readTVar
writeRef :: forall a. Ref STM a -> a -> STM ()
writeRef = TVar a -> a -> STM ()
Ref STM a -> a -> STM ()
forall a. TVar a -> a -> STM ()
writeTVar
instance MonadRef m => MonadRef (ContT r m) where
type Ref (ContT r m) = Ref m
newRef :: forall a. a -> ContT r m (Ref (ContT r m) a)
newRef a
r = m (Ref (ContT r m) a) -> ContT r m (Ref (ContT r m) a)
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Ref (ContT r m) a) -> ContT r m (Ref (ContT r m) a))
-> m (Ref (ContT r m) a) -> ContT r m (Ref (ContT r m) a)
forall a b. (a -> b) -> a -> b
$ a -> m (Ref m a)
forall a. a -> m (Ref m a)
forall (m :: * -> *) a. MonadRef m => a -> m (Ref m a)
newRef a
r
readRef :: forall a. Ref (ContT r m) a -> ContT r m a
readRef Ref (ContT r m) a
r = m a -> ContT r m a
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ContT r m a) -> m a -> ContT r m a
forall a b. (a -> b) -> a -> b
$ Ref m a -> m a
forall a. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m a
Ref (ContT r m) a
r
writeRef :: forall a. Ref (ContT r m) a -> a -> ContT r m ()
writeRef Ref (ContT r m) a
r a
x = m () -> ContT r m ()
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ContT r m ()) -> m () -> ContT r m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> a -> m ()
forall a. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
Ref (ContT r m) a
r a
x
modifyRef :: forall a. Ref (ContT r m) a -> (a -> a) -> ContT r m ()
modifyRef Ref (ContT r m) a
r a -> a
f = m () -> ContT r m ()
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ContT r m ()) -> m () -> ContT r m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef Ref m a
Ref (ContT r m) a
r a -> a
f
modifyRef' :: forall a. Ref (ContT r m) a -> (a -> a) -> ContT r m ()
modifyRef' Ref (ContT r m) a
r a -> a
f = m () -> ContT r m ()
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ContT r m ()) -> m () -> ContT r m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef' Ref m a
Ref (ContT r m) a
r a -> a
f
#if !MIN_VERSION_transformers(0,6,0)
instance (Error e, MonadRef m) => MonadRef (ErrorT e m) where
type Ref (ErrorT e m) = Ref m
newRef r = lift $ newRef r
readRef r = lift $ readRef r
writeRef r x = lift $ writeRef r x
modifyRef r f = lift $ modifyRef r f
modifyRef' r f = lift $ modifyRef' r f
#endif /* !MIN_VERSION_transformers(0,6,0) */
#if MIN_VERSION_transformers(0,4,0)
instance (MonadRef m) => MonadRef (ExceptT e m) where
type Ref (ExceptT e m) = Ref m
newRef :: forall a. a -> ExceptT e m (Ref (ExceptT e m) a)
newRef a
r = m (Ref (ExceptT e m) a) -> ExceptT e m (Ref (ExceptT e m) a)
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Ref (ExceptT e m) a) -> ExceptT e m (Ref (ExceptT e m) a))
-> m (Ref (ExceptT e m) a) -> ExceptT e m (Ref (ExceptT e m) a)
forall a b. (a -> b) -> a -> b
$ a -> m (Ref m a)
forall a. a -> m (Ref m a)
forall (m :: * -> *) a. MonadRef m => a -> m (Ref m a)
newRef a
r
readRef :: forall a. Ref (ExceptT e m) a -> ExceptT e m a
readRef Ref (ExceptT e m) a
r = m a -> ExceptT e m a
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ExceptT e m a) -> m a -> ExceptT e m a
forall a b. (a -> b) -> a -> b
$ Ref m a -> m a
forall a. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m a
Ref (ExceptT e m) a
r
writeRef :: forall a. Ref (ExceptT e m) a -> a -> ExceptT e m ()
writeRef Ref (ExceptT e m) a
r a
x = m () -> ExceptT e m ()
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ExceptT e m ()) -> m () -> ExceptT e m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> a -> m ()
forall a. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
Ref (ExceptT e m) a
r a
x
modifyRef :: forall a. Ref (ExceptT e m) a -> (a -> a) -> ExceptT e m ()
modifyRef Ref (ExceptT e m) a
r a -> a
f = m () -> ExceptT e m ()
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ExceptT e m ()) -> m () -> ExceptT e m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef Ref m a
Ref (ExceptT e m) a
r a -> a
f
modifyRef' :: forall a. Ref (ExceptT e m) a -> (a -> a) -> ExceptT e m ()
modifyRef' Ref (ExceptT e m) a
r a -> a
f = m () -> ExceptT e m ()
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ExceptT e m ()) -> m () -> ExceptT e m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef' Ref m a
Ref (ExceptT e m) a
r a -> a
f
#endif /* MIN_VERSION_transformers(0,4,0) */
instance MonadRef m => MonadRef (IdentityT m) where
type Ref (IdentityT m) = Ref m
newRef :: forall a. a -> IdentityT m (Ref (IdentityT m) a)
newRef a
r = m (Ref (IdentityT m) a) -> IdentityT m (Ref (IdentityT m) a)
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Ref (IdentityT m) a) -> IdentityT m (Ref (IdentityT m) a))
-> m (Ref (IdentityT m) a) -> IdentityT m (Ref (IdentityT m) a)
forall a b. (a -> b) -> a -> b
$ a -> m (Ref m a)
forall a. a -> m (Ref m a)
forall (m :: * -> *) a. MonadRef m => a -> m (Ref m a)
newRef a
r
readRef :: forall a. Ref (IdentityT m) a -> IdentityT m a
readRef Ref (IdentityT m) a
r = m a -> IdentityT m a
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> IdentityT m a) -> m a -> IdentityT m a
forall a b. (a -> b) -> a -> b
$ Ref m a -> m a
forall a. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m a
Ref (IdentityT m) a
r
writeRef :: forall a. Ref (IdentityT m) a -> a -> IdentityT m ()
writeRef Ref (IdentityT m) a
r a
x = m () -> IdentityT m ()
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> IdentityT m ()) -> m () -> IdentityT m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> a -> m ()
forall a. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
Ref (IdentityT m) a
r a
x
modifyRef :: forall a. Ref (IdentityT m) a -> (a -> a) -> IdentityT m ()
modifyRef Ref (IdentityT m) a
r a -> a
f = m () -> IdentityT m ()
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> IdentityT m ()) -> m () -> IdentityT m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef Ref m a
Ref (IdentityT m) a
r a -> a
f
modifyRef' :: forall a. Ref (IdentityT m) a -> (a -> a) -> IdentityT m ()
modifyRef' Ref (IdentityT m) a
r a -> a
f = m () -> IdentityT m ()
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> IdentityT m ()) -> m () -> IdentityT m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef' Ref m a
Ref (IdentityT m) a
r a -> a
f
#if !MIN_VERSION_transformers(0,6,0)
instance MonadRef m => MonadRef (ListT m) where
type Ref (ListT m) = Ref m
newRef r = lift $ newRef r
readRef r = lift $ readRef r
writeRef r x = lift $ writeRef r x
modifyRef r f = lift $ modifyRef r f
modifyRef' r f = lift $ modifyRef' r f
#endif /* !MIN_VERSION_transformers(0,6,0) */
instance MonadRef m => MonadRef (MaybeT m) where
type Ref (MaybeT m) = Ref m
newRef :: forall a. a -> MaybeT m (Ref (MaybeT m) a)
newRef a
r = m (Ref (MaybeT m) a) -> MaybeT m (Ref (MaybeT m) a)
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Ref (MaybeT m) a) -> MaybeT m (Ref (MaybeT m) a))
-> m (Ref (MaybeT m) a) -> MaybeT m (Ref (MaybeT m) a)
forall a b. (a -> b) -> a -> b
$ a -> m (Ref m a)
forall a. a -> m (Ref m a)
forall (m :: * -> *) a. MonadRef m => a -> m (Ref m a)
newRef a
r
readRef :: forall a. Ref (MaybeT m) a -> MaybeT m a
readRef Ref (MaybeT m) a
r = m a -> MaybeT m a
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> MaybeT m a) -> m a -> MaybeT m a
forall a b. (a -> b) -> a -> b
$ Ref m a -> m a
forall a. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m a
Ref (MaybeT m) a
r
writeRef :: forall a. Ref (MaybeT m) a -> a -> MaybeT m ()
writeRef Ref (MaybeT m) a
r a
x = m () -> MaybeT m ()
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> MaybeT m ()) -> m () -> MaybeT m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> a -> m ()
forall a. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
Ref (MaybeT m) a
r a
x
modifyRef :: forall a. Ref (MaybeT m) a -> (a -> a) -> MaybeT m ()
modifyRef Ref (MaybeT m) a
r a -> a
f = m () -> MaybeT m ()
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> MaybeT m ()) -> m () -> MaybeT m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef Ref m a
Ref (MaybeT m) a
r a -> a
f
modifyRef' :: forall a. Ref (MaybeT m) a -> (a -> a) -> MaybeT m ()
modifyRef' Ref (MaybeT m) a
r a -> a
f = m () -> MaybeT m ()
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> MaybeT m ()) -> m () -> MaybeT m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef' Ref m a
Ref (MaybeT m) a
r a -> a
f
instance MonadRef m => MonadRef (ReaderT r m) where
type Ref (ReaderT r m) = Ref m
newRef :: forall a. a -> ReaderT r m (Ref (ReaderT r m) a)
newRef a
r = m (Ref (ReaderT r m) a) -> ReaderT r m (Ref (ReaderT r m) a)
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Ref (ReaderT r m) a) -> ReaderT r m (Ref (ReaderT r m) a))
-> m (Ref (ReaderT r m) a) -> ReaderT r m (Ref (ReaderT r m) a)
forall a b. (a -> b) -> a -> b
$ a -> m (Ref m a)
forall a. a -> m (Ref m a)
forall (m :: * -> *) a. MonadRef m => a -> m (Ref m a)
newRef a
r
readRef :: forall a. Ref (ReaderT r m) a -> ReaderT r m a
readRef Ref (ReaderT r m) a
r = m a -> ReaderT r m a
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ReaderT r m a) -> m a -> ReaderT r m a
forall a b. (a -> b) -> a -> b
$ Ref m a -> m a
forall a. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m a
Ref (ReaderT r m) a
r
writeRef :: forall a. Ref (ReaderT r m) a -> a -> ReaderT r m ()
writeRef Ref (ReaderT r m) a
r a
x = m () -> ReaderT r m ()
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ReaderT r m ()) -> m () -> ReaderT r m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> a -> m ()
forall a. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
Ref (ReaderT r m) a
r a
x
modifyRef :: forall a. Ref (ReaderT r m) a -> (a -> a) -> ReaderT r m ()
modifyRef Ref (ReaderT r m) a
r a -> a
f = m () -> ReaderT r m ()
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ReaderT r m ()) -> m () -> ReaderT r m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef Ref m a
Ref (ReaderT r m) a
r a -> a
f
modifyRef' :: forall a. Ref (ReaderT r m) a -> (a -> a) -> ReaderT r m ()
modifyRef' Ref (ReaderT r m) a
r a -> a
f = m () -> ReaderT r m ()
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ReaderT r m ()) -> m () -> ReaderT r m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef' Ref m a
Ref (ReaderT r m) a
r a -> a
f
instance MonadRef m => MonadRef (Lazy.StateT s m) where
type Ref (Lazy.StateT s m) = Ref m
newRef :: forall a. a -> StateT s m (Ref (StateT s m) a)
newRef a
r = m (Ref (StateT s m) a) -> StateT s m (Ref (StateT s m) a)
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Ref (StateT s m) a) -> StateT s m (Ref (StateT s m) a))
-> m (Ref (StateT s m) a) -> StateT s m (Ref (StateT s m) a)
forall a b. (a -> b) -> a -> b
$ a -> m (Ref m a)
forall a. a -> m (Ref m a)
forall (m :: * -> *) a. MonadRef m => a -> m (Ref m a)
newRef a
r
readRef :: forall a. Ref (StateT s m) a -> StateT s m a
readRef Ref (StateT s m) a
r = m a -> StateT s m a
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT s m a) -> m a -> StateT s m a
forall a b. (a -> b) -> a -> b
$ Ref m a -> m a
forall a. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m a
Ref (StateT s m) a
r
writeRef :: forall a. Ref (StateT s m) a -> a -> StateT s m ()
writeRef Ref (StateT s m) a
r a
x = m () -> StateT s m ()
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> StateT s m ()) -> m () -> StateT s m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> a -> m ()
forall a. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
Ref (StateT s m) a
r a
x
modifyRef :: forall a. Ref (StateT s m) a -> (a -> a) -> StateT s m ()
modifyRef Ref (StateT s m) a
r a -> a
f = m () -> StateT s m ()
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> StateT s m ()) -> m () -> StateT s m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef Ref m a
Ref (StateT s m) a
r a -> a
f
modifyRef' :: forall a. Ref (StateT s m) a -> (a -> a) -> StateT s m ()
modifyRef' Ref (StateT s m) a
r a -> a
f = m () -> StateT s m ()
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> StateT s m ()) -> m () -> StateT s m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef' Ref m a
Ref (StateT s m) a
r a -> a
f
instance MonadRef m => MonadRef (Strict.StateT s m) where
type Ref (Strict.StateT s m) = Ref m
newRef :: forall a. a -> StateT s m (Ref (StateT s m) a)
newRef a
r = m (Ref (StateT s m) a) -> StateT s m (Ref (StateT s m) a)
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Ref (StateT s m) a) -> StateT s m (Ref (StateT s m) a))
-> m (Ref (StateT s m) a) -> StateT s m (Ref (StateT s m) a)
forall a b. (a -> b) -> a -> b
$ a -> m (Ref m a)
forall a. a -> m (Ref m a)
forall (m :: * -> *) a. MonadRef m => a -> m (Ref m a)
newRef a
r
readRef :: forall a. Ref (StateT s m) a -> StateT s m a
readRef Ref (StateT s m) a
r = m a -> StateT s m a
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> StateT s m a) -> m a -> StateT s m a
forall a b. (a -> b) -> a -> b
$ Ref m a -> m a
forall a. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m a
Ref (StateT s m) a
r
writeRef :: forall a. Ref (StateT s m) a -> a -> StateT s m ()
writeRef Ref (StateT s m) a
r a
x = m () -> StateT s m ()
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> StateT s m ()) -> m () -> StateT s m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> a -> m ()
forall a. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
Ref (StateT s m) a
r a
x
modifyRef :: forall a. Ref (StateT s m) a -> (a -> a) -> StateT s m ()
modifyRef Ref (StateT s m) a
r a -> a
f = m () -> StateT s m ()
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> StateT s m ()) -> m () -> StateT s m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef Ref m a
Ref (StateT s m) a
r a -> a
f
modifyRef' :: forall a. Ref (StateT s m) a -> (a -> a) -> StateT s m ()
modifyRef' Ref (StateT s m) a
r a -> a
f = m () -> StateT s m ()
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> StateT s m ()) -> m () -> StateT s m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef' Ref m a
Ref (StateT s m) a
r a -> a
f
instance (Monoid w, MonadRef m) => MonadRef (Lazy.WriterT w m) where
type Ref (Lazy.WriterT w m) = Ref m
newRef :: forall a. a -> WriterT w m (Ref (WriterT w m) a)
newRef a
r = m (Ref (WriterT w m) a) -> WriterT w m (Ref (WriterT w m) a)
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Ref (WriterT w m) a) -> WriterT w m (Ref (WriterT w m) a))
-> m (Ref (WriterT w m) a) -> WriterT w m (Ref (WriterT w m) a)
forall a b. (a -> b) -> a -> b
$ a -> m (Ref m a)
forall a. a -> m (Ref m a)
forall (m :: * -> *) a. MonadRef m => a -> m (Ref m a)
newRef a
r
readRef :: forall a. Ref (WriterT w m) a -> WriterT w m a
readRef Ref (WriterT w m) a
r = m a -> WriterT w m a
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a) -> m a -> WriterT w m a
forall a b. (a -> b) -> a -> b
$ Ref m a -> m a
forall a. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m a
Ref (WriterT w m) a
r
writeRef :: forall a. Ref (WriterT w m) a -> a -> WriterT w m ()
writeRef Ref (WriterT w m) a
r a
x = m () -> WriterT w m ()
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> WriterT w m ()) -> m () -> WriterT w m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> a -> m ()
forall a. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
Ref (WriterT w m) a
r a
x
modifyRef :: forall a. Ref (WriterT w m) a -> (a -> a) -> WriterT w m ()
modifyRef Ref (WriterT w m) a
r a -> a
f = m () -> WriterT w m ()
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> WriterT w m ()) -> m () -> WriterT w m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef Ref m a
Ref (WriterT w m) a
r a -> a
f
modifyRef' :: forall a. Ref (WriterT w m) a -> (a -> a) -> WriterT w m ()
modifyRef' Ref (WriterT w m) a
r a -> a
f = m () -> WriterT w m ()
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> WriterT w m ()) -> m () -> WriterT w m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef' Ref m a
Ref (WriterT w m) a
r a -> a
f
instance (Monoid w, MonadRef m) => MonadRef (Strict.WriterT w m) where
type Ref (Strict.WriterT w m) = Ref m
newRef :: forall a. a -> WriterT w m (Ref (WriterT w m) a)
newRef a
r = m (Ref (WriterT w m) a) -> WriterT w m (Ref (WriterT w m) a)
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Ref (WriterT w m) a) -> WriterT w m (Ref (WriterT w m) a))
-> m (Ref (WriterT w m) a) -> WriterT w m (Ref (WriterT w m) a)
forall a b. (a -> b) -> a -> b
$ a -> m (Ref m a)
forall a. a -> m (Ref m a)
forall (m :: * -> *) a. MonadRef m => a -> m (Ref m a)
newRef a
r
readRef :: forall a. Ref (WriterT w m) a -> WriterT w m a
readRef Ref (WriterT w m) a
r = m a -> WriterT w m a
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> WriterT w m a) -> m a -> WriterT w m a
forall a b. (a -> b) -> a -> b
$ Ref m a -> m a
forall a. Ref m a -> m a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref m a
Ref (WriterT w m) a
r
writeRef :: forall a. Ref (WriterT w m) a -> a -> WriterT w m ()
writeRef Ref (WriterT w m) a
r a
x = m () -> WriterT w m ()
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> WriterT w m ()) -> m () -> WriterT w m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> a -> m ()
forall a. Ref m a -> a -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> m ()
writeRef Ref m a
Ref (WriterT w m) a
r a
x
modifyRef :: forall a. Ref (WriterT w m) a -> (a -> a) -> WriterT w m ()
modifyRef Ref (WriterT w m) a
r a -> a
f = m () -> WriterT w m ()
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> WriterT w m ()) -> m () -> WriterT w m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef Ref m a
Ref (WriterT w m) a
r a -> a
f
modifyRef' :: forall a. Ref (WriterT w m) a -> (a -> a) -> WriterT w m ()
modifyRef' Ref (WriterT w m) a
r a -> a
f = m () -> WriterT w m ()
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> WriterT w m ()) -> m () -> WriterT w m ()
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> a) -> m ()
forall a. Ref m a -> (a -> a) -> m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> (a -> a) -> m ()
modifyRef' Ref m a
Ref (WriterT w m) a
r a -> a
f
instance MonadAtomicRef IO where
atomicModifyRef :: forall a b. Ref IO a -> (a -> (a, b)) -> IO b
atomicModifyRef = IORef a -> (a -> (a, b)) -> IO b
Ref IO a -> (a -> (a, b)) -> IO b
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef
#if MIN_VERSION_base(4,6,0)
atomicModifyRef' :: forall a b. Ref IO a -> (a -> (a, b)) -> IO b
atomicModifyRef' = IORef a -> (a -> (a, b)) -> IO b
Ref IO a -> (a -> (a, b)) -> IO b
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef'
#endif /* MIN_VERSION_base(4,6,0) */
instance MonadAtomicRef (ST s) where
atomicModifyRef :: forall a b. Ref (ST s) a -> (a -> (a, b)) -> ST s b
atomicModifyRef Ref (ST s) a
r a -> (a, b)
f = do
v <- Ref (ST s) a -> ST s a
forall a. Ref (ST s) a -> ST s a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref (ST s) a
r
let (a, b) = f v
writeRef r a
return b
atomicModifyRef' :: forall a b. Ref (ST s) a -> (a -> (a, b)) -> ST s b
atomicModifyRef' Ref (ST s) a
r a -> (a, b)
f = do
v <- Ref (ST s) a -> ST s a
forall a. Ref (ST s) a -> ST s a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref (ST s) a
r
let (a, b) = f v
writeRef r $! a
return b
instance MonadAtomicRef STM where
atomicModifyRef :: forall a b. Ref STM a -> (a -> (a, b)) -> STM b
atomicModifyRef Ref STM a
r a -> (a, b)
f = do x <- Ref STM a -> STM a
forall a. Ref STM a -> STM a
forall (m :: * -> *) a. MonadRef m => Ref m a -> m a
readRef Ref STM a
r
let (x', y) = f x
writeRef r x'
return y
instance MonadAtomicRef m => MonadAtomicRef (ContT r m) where
atomicModifyRef :: forall a b. Ref (ContT r m) a -> (a -> (a, b)) -> ContT r m b
atomicModifyRef Ref (ContT r m) a
r a -> (a, b)
f = m b -> ContT r m b
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> ContT r m b) -> m b -> ContT r m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef Ref m a
Ref (ContT r m) a
r a -> (a, b)
f
atomicModifyRef' :: forall a b. Ref (ContT r m) a -> (a -> (a, b)) -> ContT r m b
atomicModifyRef' Ref (ContT r m) a
r a -> (a, b)
f = m b -> ContT r m b
forall (m :: * -> *) a. Monad m => m a -> ContT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> ContT r m b) -> m b -> ContT r m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef' Ref m a
Ref (ContT r m) a
r a -> (a, b)
f
#if !MIN_VERSION_transformers(0,6,0)
instance (Error e, MonadAtomicRef m) => MonadAtomicRef (ErrorT e m) where
atomicModifyRef r f = lift $ atomicModifyRef r f
atomicModifyRef' r f = lift $ atomicModifyRef' r f
#endif /* !MIN_VERSION_transformers(0,6,0) */
instance MonadAtomicRef m => MonadAtomicRef (IdentityT m) where
atomicModifyRef :: forall a b. Ref (IdentityT m) a -> (a -> (a, b)) -> IdentityT m b
atomicModifyRef Ref (IdentityT m) a
r a -> (a, b)
f = m b -> IdentityT m b
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> IdentityT m b) -> m b -> IdentityT m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef Ref m a
Ref (IdentityT m) a
r a -> (a, b)
f
atomicModifyRef' :: forall a b. Ref (IdentityT m) a -> (a -> (a, b)) -> IdentityT m b
atomicModifyRef' Ref (IdentityT m) a
r a -> (a, b)
f = m b -> IdentityT m b
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> IdentityT m b) -> m b -> IdentityT m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef' Ref m a
Ref (IdentityT m) a
r a -> (a, b)
f
#if !MIN_VERSION_transformers(0,6,0)
instance MonadAtomicRef m => MonadAtomicRef (ListT m) where
atomicModifyRef r f = lift $ atomicModifyRef r f
atomicModifyRef' r f = lift $ atomicModifyRef' r f
#endif /* !MIN_VERSION_transformers(0,6,0) */
instance MonadAtomicRef m => MonadAtomicRef (MaybeT m) where
atomicModifyRef :: forall a b. Ref (MaybeT m) a -> (a -> (a, b)) -> MaybeT m b
atomicModifyRef Ref (MaybeT m) a
r a -> (a, b)
f = m b -> MaybeT m b
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> MaybeT m b) -> m b -> MaybeT m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef Ref m a
Ref (MaybeT m) a
r a -> (a, b)
f
atomicModifyRef' :: forall a b. Ref (MaybeT m) a -> (a -> (a, b)) -> MaybeT m b
atomicModifyRef' Ref (MaybeT m) a
r a -> (a, b)
f = m b -> MaybeT m b
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> MaybeT m b) -> m b -> MaybeT m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef' Ref m a
Ref (MaybeT m) a
r a -> (a, b)
f
instance MonadAtomicRef m => MonadAtomicRef (ReaderT r m) where
atomicModifyRef :: forall a b. Ref (ReaderT r m) a -> (a -> (a, b)) -> ReaderT r m b
atomicModifyRef Ref (ReaderT r m) a
r a -> (a, b)
f = m b -> ReaderT r m b
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> ReaderT r m b) -> m b -> ReaderT r m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef Ref m a
Ref (ReaderT r m) a
r a -> (a, b)
f
atomicModifyRef' :: forall a b. Ref (ReaderT r m) a -> (a -> (a, b)) -> ReaderT r m b
atomicModifyRef' Ref (ReaderT r m) a
r a -> (a, b)
f = m b -> ReaderT r m b
forall (m :: * -> *) a. Monad m => m a -> ReaderT r m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> ReaderT r m b) -> m b -> ReaderT r m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef' Ref m a
Ref (ReaderT r m) a
r a -> (a, b)
f
instance MonadAtomicRef m => MonadAtomicRef (Lazy.StateT s m) where
atomicModifyRef :: forall a b. Ref (StateT s m) a -> (a -> (a, b)) -> StateT s m b
atomicModifyRef Ref (StateT s m) a
r a -> (a, b)
f = m b -> StateT s m b
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> StateT s m b) -> m b -> StateT s m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef Ref m a
Ref (StateT s m) a
r a -> (a, b)
f
atomicModifyRef' :: forall a b. Ref (StateT s m) a -> (a -> (a, b)) -> StateT s m b
atomicModifyRef' Ref (StateT s m) a
r a -> (a, b)
f = m b -> StateT s m b
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> StateT s m b) -> m b -> StateT s m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef' Ref m a
Ref (StateT s m) a
r a -> (a, b)
f
instance MonadAtomicRef m => MonadAtomicRef (Strict.StateT s m) where
atomicModifyRef :: forall a b. Ref (StateT s m) a -> (a -> (a, b)) -> StateT s m b
atomicModifyRef Ref (StateT s m) a
r a -> (a, b)
f = m b -> StateT s m b
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> StateT s m b) -> m b -> StateT s m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef Ref m a
Ref (StateT s m) a
r a -> (a, b)
f
atomicModifyRef' :: forall a b. Ref (StateT s m) a -> (a -> (a, b)) -> StateT s m b
atomicModifyRef' Ref (StateT s m) a
r a -> (a, b)
f = m b -> StateT s m b
forall (m :: * -> *) a. Monad m => m a -> StateT s m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> StateT s m b) -> m b -> StateT s m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef' Ref m a
Ref (StateT s m) a
r a -> (a, b)
f
instance (Monoid w, MonadAtomicRef m) => MonadAtomicRef (Lazy.WriterT w m) where
atomicModifyRef :: forall a b. Ref (WriterT w m) a -> (a -> (a, b)) -> WriterT w m b
atomicModifyRef Ref (WriterT w m) a
r a -> (a, b)
f = m b -> WriterT w m b
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> WriterT w m b) -> m b -> WriterT w m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef Ref m a
Ref (WriterT w m) a
r a -> (a, b)
f
atomicModifyRef' :: forall a b. Ref (WriterT w m) a -> (a -> (a, b)) -> WriterT w m b
atomicModifyRef' Ref (WriterT w m) a
r a -> (a, b)
f = m b -> WriterT w m b
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> WriterT w m b) -> m b -> WriterT w m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef' Ref m a
Ref (WriterT w m) a
r a -> (a, b)
f
instance (Monoid w, MonadAtomicRef m) => MonadAtomicRef (Strict.WriterT w m) where
atomicModifyRef :: forall a b. Ref (WriterT w m) a -> (a -> (a, b)) -> WriterT w m b
atomicModifyRef Ref (WriterT w m) a
r a -> (a, b)
f = m b -> WriterT w m b
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> WriterT w m b) -> m b -> WriterT w m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef Ref m a
Ref (WriterT w m) a
r a -> (a, b)
f
atomicModifyRef' :: forall a b. Ref (WriterT w m) a -> (a -> (a, b)) -> WriterT w m b
atomicModifyRef' Ref (WriterT w m) a
r a -> (a, b)
f = m b -> WriterT w m b
forall (m :: * -> *) a. Monad m => m a -> WriterT w m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m b -> WriterT w m b) -> m b -> WriterT w m b
forall a b. (a -> b) -> a -> b
$ Ref m a -> (a -> (a, b)) -> m b
forall a b. Ref m a -> (a -> (a, b)) -> m b
forall (m :: * -> *) a b.
MonadAtomicRef m =>
Ref m a -> (a -> (a, b)) -> m b
atomicModifyRef' Ref m a
Ref (WriterT w m) a
r a -> (a, b)
f