monad-introspect-0.1.0.0: A reader monad that gives the environment access to the entire transformer stack

Safe HaskellNone
LanguageHaskell2010

Control.Monad.Introspect.Class

Contents

Synopsis

Abstract interface

class (Representational r, MonadIntrospectTrans IdentityT r m) => MonadIntrospect (r :: (* -> *) -> *) (m :: * -> *) where Source #

A monad with introspection capability is able to query an environment r that is parameterized by the monad itself, i.e. can contain effectful functions.

The caveat is that sometimes the monad changes (e.g. we locally run a transformer, or we globally run our transformer steck), so the monad in the environment can "desync" from the ambient monad. This warrants a more general class: MonadIntrospectTrans, of which MonadIntrospect is a special case.

The machinery sometimes requires newtype wrapping/unwrapping the monad that goes to the environment. We use/require Coercible for that, as the "functorial" operations are deemed expensive. The constraint Representational r ensures that the environment can be coerced provided the monad can be coerced.

Otherwise the interface is identical to that of MonadReader.

Methods

introspect :: m (r m) Source #

Essentially ask.

substitute :: (r m -> r m) -> m a -> m a Source #

Essentially local.

Instances
(Representational r, MonadIntrospectTrans (IdentityT :: (Type -> Type) -> Type -> Type) r m) => MonadIntrospect r m Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspect :: m (r m) Source #

substitute :: (r m -> r m) -> m a -> m a Source #

class (Monad m, MonadTrans t) => MonadIntrospectTrans (t :: (* -> *) -> * -> *) (r :: (* -> *) -> *) (m :: * -> *) | m -> t where Source #

If the ambient monad is m and the environment r has additional effects t, we can ask for that environment, or substitute it. Multiple (or zero) effects can be combined into a single t with ComposeT (or IdentityT).

Methods

introspectTrans :: m (r (t m)) Source #

Essentially ask.

substituteTrans :: (r (t m) -> r (t m)) -> m a -> m a Source #

Essentially local.

Instances
(Representational r, MonadTrans t, MonadIntrospectTrans (ComposeT t MaybeT) r m) => MonadIntrospectTrans t r (MaybeT m) Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspectTrans :: MaybeT m (r (t (MaybeT m))) Source #

substituteTrans :: (r (t (MaybeT m)) -> r (t (MaybeT m))) -> MaybeT m a -> MaybeT m a Source #

(Representational r, MonadTrans t, MonadIntrospectTrans (ComposeT t ListT) r m) => MonadIntrospectTrans t r (ListT m) Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspectTrans :: ListT m (r (t (ListT m))) Source #

substituteTrans :: (r (t (ListT m)) -> r (t (ListT m))) -> ListT m a -> ListT m a Source #

(Representational r, Monoid w, MonadTrans t, MonadIntrospectTrans (ComposeT t (WriterT w)) r m) => MonadIntrospectTrans t r (WriterT w m) Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspectTrans :: WriterT w m (r (t (WriterT w m))) Source #

substituteTrans :: (r (t (WriterT w m)) -> r (t (WriterT w m))) -> WriterT w m a -> WriterT w m a Source #

(Representational r, Monoid w, MonadTrans t, MonadIntrospectTrans (ComposeT t (WriterT w)) r m) => MonadIntrospectTrans t r (WriterT w m) Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspectTrans :: WriterT w m (r (t (WriterT w m))) Source #

substituteTrans :: (r (t (WriterT w m)) -> r (t (WriterT w m))) -> WriterT w m a -> WriterT w m a Source #

(Representational r, MonadTrans t, MonadIntrospectTrans (ComposeT t (StateT s)) r m) => MonadIntrospectTrans t r (StateT s m) Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspectTrans :: StateT s m (r (t (StateT s m))) Source #

substituteTrans :: (r (t (StateT s m)) -> r (t (StateT s m))) -> StateT s m a -> StateT s m a Source #

(Representational r, MonadTrans t, MonadIntrospectTrans (ComposeT t (StateT s)) r m) => MonadIntrospectTrans t r (StateT s m) Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspectTrans :: StateT s m (r (t (StateT s m))) Source #

substituteTrans :: (r (t (StateT s m)) -> r (t (StateT s m))) -> StateT s m a -> StateT s m a Source #

(Representational r, Error e, MonadTrans t, MonadIntrospectTrans (ComposeT t (ErrorT e)) r m) => MonadIntrospectTrans t r (ErrorT e m) Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspectTrans :: ErrorT e m (r (t (ErrorT e m))) Source #

substituteTrans :: (r (t (ErrorT e m)) -> r (t (ErrorT e m))) -> ErrorT e m a -> ErrorT e m a Source #

(Representational r, MonadTrans t, MonadIntrospectTrans (ComposeT t (ExceptT e)) r m) => MonadIntrospectTrans t r (ExceptT e m) Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspectTrans :: ExceptT e m (r (t (ExceptT e m))) Source #

substituteTrans :: (r (t (ExceptT e m)) -> r (t (ExceptT e m))) -> ExceptT e m a -> ExceptT e m a Source #

(Representational r, MonadTrans t, MonadIntrospectTrans (ComposeT t (IdentityT :: (Type -> Type) -> Type -> Type)) r m) => MonadIntrospectTrans t r (IdentityT m) Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspectTrans :: IdentityT m (r (t (IdentityT m))) Source #

substituteTrans :: (r (t (IdentityT m)) -> r (t (IdentityT m))) -> IdentityT m a -> IdentityT m a Source #

(Representational r, MonadTrans t, MonadIntrospectTrans (ComposeT t (ReaderT e :: (Type -> Type) -> Type -> Type)) r m) => MonadIntrospectTrans t r (ReaderT e m) Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspectTrans :: ReaderT e m (r (t (ReaderT e m))) Source #

substituteTrans :: (r (t (ReaderT e m)) -> r (t (ReaderT e m))) -> ReaderT e m a -> ReaderT e m a Source #

(Representational r, MonadTrans t, MonadIntrospectTrans (ComposeT t (ContT e)) r m) => MonadIntrospectTrans t r (ContT e m) Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspectTrans :: ContT e m (r (t (ContT e m))) Source #

substituteTrans :: (r (t (ContT e m)) -> r (t (ContT e m))) -> ContT e m a -> ContT e m a Source #

(Monad m, MonadTrans t) => MonadIntrospectTrans t r (IntrospectT t r m) Source # 
Instance details

Defined in Control.Monad.Trans.Introspect

Methods

introspectTrans :: IntrospectT t r m (r (t (IntrospectT t r m))) Source #

substituteTrans :: (r (t (IntrospectT t r m)) -> r (t (IntrospectT t r m))) -> IntrospectT t r m a -> IntrospectT t r m a Source #

(Representational r, Monoid w, MonadTrans t, MonadIntrospectTrans (ComposeT t (RWST e w s)) r m) => MonadIntrospectTrans t r (RWST e w s m) Source # 
Instance details

Defined in Control.Monad.Introspect.Class

Methods

introspectTrans :: RWST e w s m (r (t (RWST e w s m))) Source #

substituteTrans :: (r (t (RWST e w s m)) -> r (t (RWST e w s m))) -> RWST e w s m a -> RWST e w s m a Source #

Utility functions for coercing environments

liftTransEnv :: (Representational r, Coercible m n) => r m -> r n Source #

liftTransMapper :: (Representational r, Coercible m n) => (r m -> r m) -> r n -> r n Source #