{-# LANGUAGE CPP
, NoImplicitPrelude
, RankNTypes
, TypeFamilies
, FunctionalDependencies
, FlexibleInstances
, UndecidableInstances
, MultiParamTypeClasses #-}
{-# LANGUAGE Safe #-}
#if MIN_VERSION_transformers(0,4,0)
{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
#endif
module Control.Monad.Trans.Control
(
MonadTransControl(..), Run
, RunDefault, defaultLiftWith, defaultRestoreT
, RunDefault2, defaultLiftWith2, defaultRestoreT2
, MonadBaseControl (..), RunInBase
, ComposeSt, RunInBaseDefault, defaultLiftBaseWith, defaultRestoreM
, control, controlT, embed, embed_, captureT, captureM
, liftBaseOp, liftBaseOp_
, liftBaseDiscard, liftBaseOpDiscard
, liftThrough
) where
import Data.Function ( (.), ($), const )
import Data.Monoid ( Monoid, mempty )
import Control.Monad ( Monad, (>>=), return, liftM )
import System.IO ( IO )
import Data.Maybe ( Maybe )
import Data.Either ( Either )
import Control.Monad ( void )
import Prelude ( id )
import Control.Monad.ST.Lazy.Safe ( ST )
import qualified Control.Monad.ST.Safe as Strict ( ST )
import Control.Monad.STM ( STM )
import Control.Monad.Trans.Class ( MonadTrans )
import Control.Monad.Trans.Identity ( IdentityT(IdentityT), runIdentityT )
import Control.Monad.Trans.Maybe ( MaybeT (MaybeT), runMaybeT )
import Control.Monad.Trans.Reader ( ReaderT (ReaderT), runReaderT )
import Control.Monad.Trans.State ( StateT (StateT), runStateT )
import Control.Monad.Trans.Writer ( WriterT (WriterT), runWriterT )
import Control.Monad.Trans.RWS ( RWST (RWST), runRWST )
import Control.Monad.Trans.Except ( ExceptT (ExceptT), runExceptT )
#if !(MIN_VERSION_transformers(0,6,0))
import Control.Monad.Trans.List ( ListT (ListT), runListT )
import Control.Monad.Trans.Error ( ErrorT (ErrorT), runErrorT, Error )
#endif
import qualified Control.Monad.Trans.RWS.Strict as Strict ( RWST (RWST), runRWST )
import qualified Control.Monad.Trans.State.Strict as Strict ( StateT (StateT), runStateT )
import qualified Control.Monad.Trans.Writer.Strict as Strict ( WriterT(WriterT), runWriterT )
import Data.Functor.Identity ( Identity )
import Control.Monad.Base ( MonadBase )
class MonadTrans t => MonadTransControl t where
type StT t a :: *
liftWith :: Monad m => (Run t -> m a) -> t m a
restoreT :: Monad m => m (StT t a) -> t m a
type Run t = forall n b. Monad n => t n b -> n (StT t b)
type RunDefault t t' = forall n b. Monad n => t n b -> n (StT t' b)
defaultLiftWith :: (Monad m, MonadTransControl n)
=> (forall b. n m b -> t m b)
-> (forall o b. t o b -> n o b)
-> (RunDefault t n -> m a)
-> t m a
defaultLiftWith :: forall (m :: * -> *) (n :: (* -> *) -> * -> *)
(t :: (* -> *) -> * -> *) a.
(Monad m, MonadTransControl n) =>
(forall b. n m b -> t m b)
-> (forall (o :: * -> *) b. t o b -> n o b)
-> (RunDefault t n -> m a)
-> t m a
defaultLiftWith forall b. n m b -> t m b
t forall (o :: * -> *) b. t o b -> n o b
unT = \RunDefault t n -> m a
f -> forall b. n m b -> t m b
t forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
(Run t -> m a) -> t m a
liftWith forall a b. (a -> b) -> a -> b
$ \Run n
run -> RunDefault t n -> m a
f forall a b. (a -> b) -> a -> b
$ Run n
run forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (o :: * -> *) b. t o b -> n o b
unT
{-# INLINABLE defaultLiftWith #-}
defaultRestoreT :: (Monad m, MonadTransControl n)
=> (n m a -> t m a)
-> m (StT n a)
-> t m a
defaultRestoreT :: forall (m :: * -> *) (n :: (* -> *) -> * -> *) a
(t :: (* -> *) -> * -> *).
(Monad m, MonadTransControl n) =>
(n m a -> t m a) -> m (StT n a) -> t m a
defaultRestoreT n m a -> t m a
t = n m a -> t m a
t forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
m (StT t a) -> t m a
restoreT
{-# INLINABLE defaultRestoreT #-}
type RunDefault2 t n n' = forall m b. (Monad m, Monad (n' m)) => t m b -> m (StT n' (StT n b))
defaultLiftWith2 :: (Monad m, Monad (n' m), MonadTransControl n, MonadTransControl n')
=> (forall b. n (n' m) b -> t m b)
-> (forall o b. t o b -> n (n' o) b)
-> (RunDefault2 t n n' -> m a)
-> t m a
defaultLiftWith2 :: forall (m :: * -> *) (n' :: (* -> *) -> * -> *)
(n :: (* -> *) -> * -> *) (t :: (* -> *) -> * -> *) a.
(Monad m, Monad (n' m), MonadTransControl n,
MonadTransControl n') =>
(forall b. n (n' m) b -> t m b)
-> (forall (o :: * -> *) b. t o b -> n (n' o) b)
-> (RunDefault2 t n n' -> m a)
-> t m a
defaultLiftWith2 forall b. n (n' m) b -> t m b
t forall (o :: * -> *) b. t o b -> n (n' o) b
unT = \RunDefault2 t n n' -> m a
f -> forall b. n (n' m) b -> t m b
t forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
(Run t -> m a) -> t m a
liftWith forall a b. (a -> b) -> a -> b
$ \Run n
run -> forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
(Run t -> m a) -> t m a
liftWith forall a b. (a -> b) -> a -> b
$ \Run n'
run' -> RunDefault2 t n n' -> m a
f forall a b. (a -> b) -> a -> b
$ Run n'
run' forall b c a. (b -> c) -> (a -> b) -> a -> c
. Run n
run forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (o :: * -> *) b. t o b -> n (n' o) b
unT
{-# INLINABLE defaultLiftWith2 #-}
defaultRestoreT2 :: (Monad m, Monad (n' m), MonadTransControl n, MonadTransControl n')
=> (n (n' m) a -> t m a)
-> m (StT n' (StT n a))
-> t m a
defaultRestoreT2 :: forall (m :: * -> *) (n' :: (* -> *) -> * -> *)
(n :: (* -> *) -> * -> *) a (t :: (* -> *) -> * -> *).
(Monad m, Monad (n' m), MonadTransControl n,
MonadTransControl n') =>
(n (n' m) a -> t m a) -> m (StT n' (StT n a)) -> t m a
defaultRestoreT2 n (n' m) a -> t m a
t = n (n' m) a -> t m a
t forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
m (StT t a) -> t m a
restoreT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
m (StT t a) -> t m a
restoreT
{-# INLINABLE defaultRestoreT2 #-}
instance MonadTransControl IdentityT where
type StT IdentityT a = a
liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run IdentityT -> m a) -> IdentityT m a
liftWith Run IdentityT -> m a
f = forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT forall a b. (a -> b) -> a -> b
$ Run IdentityT -> m a
f forall a b. (a -> b) -> a -> b
$ forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
runIdentityT
restoreT :: forall (m :: * -> *) a.
Monad m =>
m (StT IdentityT a) -> IdentityT m a
restoreT = forall {k} (f :: k -> *) (a :: k). f a -> IdentityT f a
IdentityT
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
instance MonadTransControl MaybeT where
type StT MaybeT a = Maybe a
liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run MaybeT -> m a) -> MaybeT m a
liftWith Run MaybeT -> m a
f = forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Run MaybeT -> m a
f forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT
restoreT :: forall (m :: * -> *) a. Monad m => m (StT MaybeT a) -> MaybeT m a
restoreT = forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
#if !(MIN_VERSION_transformers(0,6,0))
instance MonadTransControl ListT where
type StT ListT a = [a]
liftWith :: forall (m :: * -> *) a. Monad m => (Run ListT -> m a) -> ListT m a
liftWith Run ListT -> m a
f = forall (m :: * -> *) a. m [a] -> ListT m a
ListT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Run ListT -> m a
f forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. ListT m a -> m [a]
runListT
restoreT :: forall (m :: * -> *) a. Monad m => m (StT ListT a) -> ListT m a
restoreT = forall (m :: * -> *) a. m [a] -> ListT m a
ListT
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
instance Error e => MonadTransControl (ErrorT e) where
type StT (ErrorT e) a = Either e a
liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run (ErrorT e) -> m a) -> ErrorT e m a
liftWith Run (ErrorT e) -> m a
f = forall e (m :: * -> *) a. m (Either e a) -> ErrorT e m a
ErrorT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Run (ErrorT e) -> m a
f forall a b. (a -> b) -> a -> b
$ forall e (m :: * -> *) a. ErrorT e m a -> m (Either e a)
runErrorT
restoreT :: forall (m :: * -> *) a.
Monad m =>
m (StT (ErrorT e) a) -> ErrorT e m a
restoreT = forall e (m :: * -> *) a. m (Either e a) -> ErrorT e m a
ErrorT
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
#endif
instance MonadTransControl (ExceptT e) where
type StT (ExceptT e) a = Either e a
liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run (ExceptT e) -> m a) -> ExceptT e m a
liftWith Run (ExceptT e) -> m a
f = forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Run (ExceptT e) -> m a
f forall a b. (a -> b) -> a -> b
$ forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT
restoreT :: forall (m :: * -> *) a.
Monad m =>
m (StT (ExceptT e) a) -> ExceptT e m a
restoreT = forall e (m :: * -> *) a. m (Either e a) -> ExceptT e m a
ExceptT
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
instance MonadTransControl (ReaderT r) where
type StT (ReaderT r) a = a
liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run (ReaderT r) -> m a) -> ReaderT r m a
liftWith Run (ReaderT r) -> m a
f = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall a b. (a -> b) -> a -> b
$ \r
r -> Run (ReaderT r) -> m a
f forall a b. (a -> b) -> a -> b
$ \ReaderT r n b
t -> forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT r n b
t r
r
restoreT :: forall (m :: * -> *) a.
Monad m =>
m (StT (ReaderT r) a) -> ReaderT r m a
restoreT = forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> b -> a
const
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
instance MonadTransControl (StateT s) where
type StT (StateT s) a = (a, s)
liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run (StateT s) -> m a) -> StateT s m a
liftWith Run (StateT s) -> m a
f = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
StateT forall a b. (a -> b) -> a -> b
$ \s
s ->
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\a
x -> (a
x, s
s))
(Run (StateT s) -> m a
f forall a b. (a -> b) -> a -> b
$ \StateT s n b
t -> forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT StateT s n b
t s
s)
restoreT :: forall (m :: * -> *) a.
Monad m =>
m (StT (StateT s) a) -> StateT s m a
restoreT = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
StateT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> b -> a
const
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
instance MonadTransControl (Strict.StateT s) where
type StT (Strict.StateT s) a = (a, s)
liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run (StateT s) -> m a) -> StateT s m a
liftWith Run (StateT s) -> m a
f = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Strict.StateT forall a b. (a -> b) -> a -> b
$ \s
s ->
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\a
x -> (a
x, s
s))
(Run (StateT s) -> m a
f forall a b. (a -> b) -> a -> b
$ \StateT s n b
t -> forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
Strict.runStateT StateT s n b
t s
s)
restoreT :: forall (m :: * -> *) a.
Monad m =>
m (StT (StateT s) a) -> StateT s m a
restoreT = forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
Strict.StateT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> b -> a
const
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
instance Monoid w => MonadTransControl (WriterT w) where
type StT (WriterT w) a = (a, w)
liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run (WriterT w) -> m a) -> WriterT w m a
liftWith Run (WriterT w) -> m a
f = forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
WriterT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\a
x -> (a
x, forall a. Monoid a => a
mempty))
(Run (WriterT w) -> m a
f forall a b. (a -> b) -> a -> b
$ forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
runWriterT)
restoreT :: forall (m :: * -> *) a.
Monad m =>
m (StT (WriterT w) a) -> WriterT w m a
restoreT = forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
WriterT
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
instance Monoid w => MonadTransControl (Strict.WriterT w) where
type StT (Strict.WriterT w) a = (a, w)
liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run (WriterT w) -> m a) -> WriterT w m a
liftWith Run (WriterT w) -> m a
f = forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
Strict.WriterT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\a
x -> (a
x, forall a. Monoid a => a
mempty))
(Run (WriterT w) -> m a
f forall a b. (a -> b) -> a -> b
$ forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
Strict.runWriterT)
restoreT :: forall (m :: * -> *) a.
Monad m =>
m (StT (WriterT w) a) -> WriterT w m a
restoreT = forall w (m :: * -> *) a. m (a, w) -> WriterT w m a
Strict.WriterT
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
instance Monoid w => MonadTransControl (RWST r w s) where
type StT (RWST r w s) a = (a, s, w)
liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run (RWST r w s) -> m a) -> RWST r w s m a
liftWith Run (RWST r w s) -> m a
f = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \r
r s
s -> forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\a
x -> (a
x, s
s, forall a. Monoid a => a
mempty))
(Run (RWST r w s) -> m a
f forall a b. (a -> b) -> a -> b
$ \RWST r w s n b
t -> forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST r w s n b
t r
r s
s)
restoreT :: forall (m :: * -> *) a.
Monad m =>
m (StT (RWST r w s) a) -> RWST r w s m a
restoreT m (StT (RWST r w s) a)
mSt = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \r
_ s
_ -> m (StT (RWST r w s) a)
mSt
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
instance Monoid w => MonadTransControl (Strict.RWST r w s) where
type StT (Strict.RWST r w s) a = (a, s, w)
liftWith :: forall (m :: * -> *) a.
Monad m =>
(Run (RWST r w s) -> m a) -> RWST r w s m a
liftWith Run (RWST r w s) -> m a
f =
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Strict.RWST forall a b. (a -> b) -> a -> b
$ \r
r s
s -> forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\a
x -> (a
x, s
s, forall a. Monoid a => a
mempty))
(Run (RWST r w s) -> m a
f forall a b. (a -> b) -> a -> b
$ \RWST r w s n b
t -> forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
Strict.runRWST RWST r w s n b
t r
r s
s)
restoreT :: forall (m :: * -> *) a.
Monad m =>
m (StT (RWST r w s) a) -> RWST r w s m a
restoreT m (StT (RWST r w s) a)
mSt = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
Strict.RWST forall a b. (a -> b) -> a -> b
$ \r
_ s
_ -> m (StT (RWST r w s) a)
mSt
{-# INLINABLE liftWith #-}
{-# INLINABLE restoreT #-}
class MonadBase b m => MonadBaseControl b m | m -> b where
type StM m a :: *
liftBaseWith :: (RunInBase m b -> b a) -> m a
restoreM :: StM m a -> m a
type RunInBase m b = forall a. m a -> b (StM m a)
#define BASE(M) \
instance MonadBaseControl (M) (M) where { \
type StM (M) a = a; \
liftBaseWith f = f id; \
restoreM = return; \
{-# INLINABLE liftBaseWith #-}; \
{-# INLINABLE restoreM #-}}
BASE(IO)
BASE(Maybe)
BASE(Either e)
BASE([])
BASE((->) r)
BASE(Identity)
BASE(STM)
BASE(Strict.ST s)
BASE( ST s)
#undef BASE
type ComposeSt t m a = StM m (StT t a)
type RunInBaseDefault t m b = forall a. t m a -> b (ComposeSt t m a)
defaultLiftBaseWith :: (MonadTransControl t, MonadBaseControl b m)
=> (RunInBaseDefault t m b -> b a) -> t m a
defaultLiftBaseWith :: forall (t :: (* -> *) -> * -> *) (b :: * -> *) (m :: * -> *) a.
(MonadTransControl t, MonadBaseControl b m) =>
(RunInBaseDefault t m b -> b a) -> t m a
defaultLiftBaseWith = \RunInBaseDefault t m b -> b a
f -> forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
(Run t -> m a) -> t m a
liftWith forall a b. (a -> b) -> a -> b
$ \Run t
run ->
forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b a) -> m a
liftBaseWith forall a b. (a -> b) -> a -> b
$ \RunInBase m b
runInBase ->
RunInBaseDefault t m b -> b a
f forall a b. (a -> b) -> a -> b
$ RunInBase m b
runInBase forall b c a. (b -> c) -> (a -> b) -> a -> c
. Run t
run
{-# INLINABLE defaultLiftBaseWith #-}
defaultRestoreM :: (MonadTransControl t, MonadBaseControl b m)
=> ComposeSt t m a -> t m a
defaultRestoreM :: forall (t :: (* -> *) -> * -> *) (b :: * -> *) (m :: * -> *) a.
(MonadTransControl t, MonadBaseControl b m) =>
ComposeSt t m a -> t m a
defaultRestoreM = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
m (StT t a) -> t m a
restoreT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
StM m a -> m a
restoreM
{-# INLINABLE defaultRestoreM #-}
#define BODY(T) { \
type StM (T m) a = ComposeSt (T) m a; \
liftBaseWith = defaultLiftBaseWith; \
restoreM = defaultRestoreM; \
{-# INLINABLE liftBaseWith #-}; \
{-# INLINABLE restoreM #-}}
#define TRANS( T) \
instance ( MonadBaseControl b m) => MonadBaseControl b (T m) where BODY(T)
#define TRANS_CTX(CTX, T) \
instance (CTX, MonadBaseControl b m) => MonadBaseControl b (T m) where BODY(T)
TRANS(IdentityT)
TRANS(MaybeT)
TRANS(ReaderT r)
TRANS(Strict.StateT s)
TRANS( StateT s)
TRANS(ExceptT e)
TRANS_CTX(Monoid w, Strict.WriterT w)
TRANS_CTX(Monoid w, WriterT w)
TRANS_CTX(Monoid w, Strict.RWST r w s)
TRANS_CTX(Monoid w, RWST r w s)
#if !(MIN_VERSION_transformers(0,6,0))
TRANS(ListT)
TRANS_CTX(Error e, ErrorT e)
#endif
#undef BODY
#undef TRANS
#undef TRANS_CTX
control :: MonadBaseControl b m => (RunInBase m b -> b (StM m a)) -> m a
control :: forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b (StM m a)) -> m a
control RunInBase m b -> b (StM m a)
f = forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b a) -> m a
liftBaseWith RunInBase m b -> b (StM m a)
f forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
StM m a -> m a
restoreM
{-# INLINABLE control #-}
controlT :: (MonadTransControl t, Monad (t m), Monad m)
=> (Run t -> m (StT t a)) -> t m a
controlT :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad (t m), Monad m) =>
(Run t -> m (StT t a)) -> t m a
controlT Run t -> m (StT t a)
f = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
(Run t -> m a) -> t m a
liftWith Run t -> m (StT t a)
f forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
m (StT t a) -> t m a
restoreT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => a -> m a
return
{-# INLINABLE controlT #-}
embed :: MonadBaseControl b m => (a -> m c) -> m (a -> b (StM m c))
embed :: forall (b :: * -> *) (m :: * -> *) a c.
MonadBaseControl b m =>
(a -> m c) -> m (a -> b (StM m c))
embed a -> m c
f = forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b a) -> m a
liftBaseWith forall a b. (a -> b) -> a -> b
$ \RunInBase m b
runInBase -> forall (m :: * -> *) a. Monad m => a -> m a
return (RunInBase m b
runInBase forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m c
f)
{-# INLINABLE embed #-}
embed_ :: MonadBaseControl b m => (a -> m ()) -> m (a -> b ())
embed_ :: forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(a -> m ()) -> m (a -> b ())
embed_ a -> m ()
f = forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b a) -> m a
liftBaseWith forall a b. (a -> b) -> a -> b
$ \RunInBase m b
runInBase -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall (f :: * -> *) a. Functor f => f a -> f ()
void forall b c a. (b -> c) -> (a -> b) -> a -> c
. RunInBase m b
runInBase forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m ()
f)
{-# INLINABLE embed_ #-}
captureT :: (MonadTransControl t, Monad (t m), Monad m) => t m (StT t ())
captureT :: forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(MonadTransControl t, Monad (t m), Monad m) =>
t m (StT t ())
captureT = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
(Run t -> m a) -> t m a
liftWith forall a b. (a -> b) -> a -> b
$ \Run t
runInM -> Run t
runInM (forall (m :: * -> *) a. Monad m => a -> m a
return ())
{-# INLINABLE captureT #-}
captureM :: MonadBaseControl b m => m (StM m ())
captureM :: forall (b :: * -> *) (m :: * -> *).
MonadBaseControl b m =>
m (StM m ())
captureM = forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b a) -> m a
liftBaseWith forall a b. (a -> b) -> a -> b
$ \RunInBase m b
runInBase -> RunInBase m b
runInBase (forall (m :: * -> *) a. Monad m => a -> m a
return ())
{-# INLINABLE captureM #-}
liftBaseOp :: MonadBaseControl b m
=> ((a -> b (StM m c)) -> b (StM m d))
-> ((a -> m c) -> m d)
liftBaseOp :: forall (b :: * -> *) (m :: * -> *) a c d.
MonadBaseControl b m =>
((a -> b (StM m c)) -> b (StM m d)) -> (a -> m c) -> m d
liftBaseOp (a -> b (StM m c)) -> b (StM m d)
f = \a -> m c
g -> forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b (StM m a)) -> m a
control forall a b. (a -> b) -> a -> b
$ \RunInBase m b
runInBase -> (a -> b (StM m c)) -> b (StM m d)
f forall a b. (a -> b) -> a -> b
$ RunInBase m b
runInBase forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m c
g
{-# INLINABLE liftBaseOp #-}
liftBaseOp_ :: MonadBaseControl b m
=> (b (StM m a) -> b (StM m c))
-> ( m a -> m c)
liftBaseOp_ :: forall (b :: * -> *) (m :: * -> *) a c.
MonadBaseControl b m =>
(b (StM m a) -> b (StM m c)) -> m a -> m c
liftBaseOp_ b (StM m a) -> b (StM m c)
f = \m a
m -> forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b (StM m a)) -> m a
control forall a b. (a -> b) -> a -> b
$ \RunInBase m b
runInBase -> b (StM m a) -> b (StM m c)
f forall a b. (a -> b) -> a -> b
$ RunInBase m b
runInBase m a
m
{-# INLINABLE liftBaseOp_ #-}
liftBaseDiscard :: MonadBaseControl b m => (b () -> b a) -> (m () -> m a)
liftBaseDiscard :: forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(b () -> b a) -> m () -> m a
liftBaseDiscard b () -> b a
f = \m ()
m -> forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b a) -> m a
liftBaseWith forall a b. (a -> b) -> a -> b
$ \RunInBase m b
runInBase -> b () -> b a
f forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ RunInBase m b
runInBase m ()
m
{-# INLINABLE liftBaseDiscard #-}
liftBaseOpDiscard :: MonadBaseControl b m
=> ((a -> b ()) -> b c)
-> (a -> m ()) -> m c
liftBaseOpDiscard :: forall (b :: * -> *) (m :: * -> *) a c.
MonadBaseControl b m =>
((a -> b ()) -> b c) -> (a -> m ()) -> m c
liftBaseOpDiscard (a -> b ()) -> b c
f a -> m ()
g = forall (b :: * -> *) (m :: * -> *) a.
MonadBaseControl b m =>
(RunInBase m b -> b a) -> m a
liftBaseWith forall a b. (a -> b) -> a -> b
$ \RunInBase m b
runInBase -> (a -> b ()) -> b c
f forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Functor f => f a -> f ()
void forall b c a. (b -> c) -> (a -> b) -> a -> c
. RunInBase m b
runInBase forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m ()
g
{-# INLINABLE liftBaseOpDiscard #-}
liftThrough
:: (MonadTransControl t, Monad (t m), Monad m)
=> (m (StT t a) -> m (StT t b))
-> t m a -> t m b
liftThrough :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(MonadTransControl t, Monad (t m), Monad m) =>
(m (StT t a) -> m (StT t b)) -> t m a -> t m b
liftThrough m (StT t a) -> m (StT t b)
f t m a
t = do
StT t b
st <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
(Run t -> m a) -> t m a
liftWith forall a b. (a -> b) -> a -> b
$ \Run t
run -> do
m (StT t a) -> m (StT t b)
f forall a b. (a -> b) -> a -> b
$ Run t
run t m a
t
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTransControl t, Monad m) =>
m (StT t a) -> t m a
restoreT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return StT t b
st