| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
MTLPrelude
Description
Reexports of most definitions from "mtl" and "transformers".
For details check out the source.
Synopsis
- class Monad m => MonadIO (m :: Type -> Type) where
- newtype Identity a = Identity {
- runIdentity :: a
- class MonadTrans (t :: (Type -> Type) -> Type -> Type) where
- class (Monoid w, MonadReader r m, MonadWriter w m, MonadState s m) => MonadRWS r w s (m :: Type -> Type) | m -> r, m -> w, m -> s
- class (Monoid w, Monad m) => MonadWriter w (m :: Type -> Type) | m -> w where
- listens :: MonadWriter w m => (w -> b) -> m a -> m (a, b)
- censor :: MonadWriter w m => (w -> w) -> m a -> m a
- class Monad m => MonadState s (m :: Type -> Type) | m -> s where
- modify' :: MonadState s m => (s -> s) -> m ()
- modify :: MonadState s m => (s -> s) -> m ()
- gets :: MonadState s m => (s -> a) -> m a
- class Monad m => MonadReader r (m :: Type -> Type) | m -> r where
- asks :: MonadReader r m => (r -> a) -> m a
- class Monad m => MonadError e (m :: Type -> Type) | m -> e where
- throwError :: e -> m a
- catchError :: m a -> (e -> m a) -> m a
- liftEither :: MonadError e m => Either e a -> m a
- class Monad m => MonadCont (m :: Type -> Type) where
- callCC :: ((a -> m b) -> m a) -> m a
- cont :: ((a -> r) -> r) -> Cont r a
- mapCont :: (r -> r) -> Cont r a -> Cont r a
- mapContT :: forall {k} m (r :: k) a. (m r -> m r) -> ContT r m a -> ContT r m a
- runCont :: Cont r a -> (a -> r) -> r
- withCont :: ((b -> r) -> a -> r) -> Cont r a -> Cont r b
- withContT :: forall {k} b m (r :: k) a. ((b -> m r) -> a -> m r) -> ContT r m a -> ContT r m b
- type Cont r = ContT r Identity
- newtype ContT (r :: k) (m :: k -> Type) a = ContT {
- runContT :: (a -> m r) -> m r
- class Error a where
- mapExcept :: (Either e a -> Either e' b) -> Except e a -> Except e' b
- mapExceptT :: (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b
- runExcept :: Except e a -> Either e a
- runExceptT :: ExceptT e m a -> m (Either e a)
- withExcept :: (e -> e') -> Except e a -> Except e' a
- withExceptT :: forall (m :: Type -> Type) e e' a. Functor m => (e -> e') -> ExceptT e m a -> ExceptT e' m a
- type Except e = ExceptT e Identity
- newtype ExceptT e (m :: Type -> Type) a = ExceptT (m (Either e a))
- evalRWS :: RWS r w s a -> r -> s -> (a, w)
- evalRWST :: Monad m => RWST r w s m a -> r -> s -> m (a, w)
- execRWS :: RWS r w s a -> r -> s -> (s, w)
- execRWST :: Monad m => RWST r w s m a -> r -> s -> m (s, w)
- mapRWS :: ((a, s, w) -> (b, s, w')) -> RWS r w s a -> RWS r w' s b
- mapRWST :: (m (a, s, w) -> n (b, s, w')) -> RWST r w s m a -> RWST r w' s n b
- runRWS :: RWS r w s a -> r -> s -> (a, s, w)
- rws :: (r -> s -> (a, s, w)) -> RWS r w s a
- withRWS :: (r' -> s -> (r, s)) -> RWS r w s a -> RWS r' w s a
- withRWST :: forall r' s r w (m :: Type -> Type) a. (r' -> s -> (r, s)) -> RWST r w s m a -> RWST r' w s m a
- type RWS r w s = RWST r w s Identity
- newtype RWST r w s (m :: Type -> Type) a = RWST {
- runRWST :: r -> s -> m (a, s, w)
- mapReader :: (a -> b) -> Reader r a -> Reader r b
- mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b
- runReader :: Reader r a -> r -> a
- withReader :: (r' -> r) -> Reader r a -> Reader r' a
- withReaderT :: forall r' r (m :: Type -> Type) a. (r' -> r) -> ReaderT r m a -> ReaderT r' m a
- type Reader r = ReaderT r Identity
- newtype ReaderT r (m :: Type -> Type) a = ReaderT {
- runReaderT :: r -> m a
- evalState :: State s a -> s -> a
- evalStateT :: Monad m => StateT s m a -> s -> m a
- execState :: State s a -> s -> s
- execStateT :: Monad m => StateT s m a -> s -> m s
- mapState :: ((a, s) -> (b, s)) -> State s a -> State s b
- mapStateT :: (m (a, s) -> n (b, s)) -> StateT s m a -> StateT s n b
- runState :: State s a -> s -> (a, s)
- withState :: (s -> s) -> State s a -> State s a
- withStateT :: forall s (m :: Type -> Type) a. (s -> s) -> StateT s m a -> StateT s m a
- type State s = StateT s Identity
- newtype StateT s (m :: Type -> Type) a = StateT {
- runStateT :: s -> m (a, s)
- execWriter :: Writer w a -> w
- execWriterT :: Monad m => WriterT w m a -> m w
- mapWriter :: ((a, w) -> (b, w')) -> Writer w a -> Writer w' b
- mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b
- runWriter :: Writer w a -> (a, w)
- type Writer w = WriterT w Identity
- newtype WriterT w (m :: Type -> Type) a = WriterT {
- runWriterT :: m (a, w)
- newtype MaybeT (m :: Type -> Type) a = MaybeT {}
- maybeToExceptT :: forall (m :: Type -> Type) e a. Functor m => e -> MaybeT m a -> ExceptT e m a
- mapMaybeT :: (m (Maybe a) -> n (Maybe b)) -> MaybeT m a -> MaybeT n b
- liftPass :: Monad m => Pass w m (Maybe a) -> Pass w (MaybeT m) a
- liftListen :: Monad m => Listen w m (Maybe a) -> Listen w (MaybeT m) a
- liftCatch :: Catch e m (Maybe a) -> Catch e (MaybeT m) a
- liftCallCC :: CallCC m (Maybe a) (Maybe b) -> CallCC (MaybeT m) a b
- exceptToMaybeT :: forall (m :: Type -> Type) e a. Functor m => ExceptT e m a -> MaybeT m a
- except :: forall (m :: Type -> Type) e a. Monad m => Either e a -> ExceptT e m a
- shiftT :: Monad m => ((a -> m r) -> ContT r m r) -> ContT r m a
- shift :: ((a -> r) -> Cont r r) -> Cont r a
- resetT :: forall (m :: Type -> Type) r r'. Monad m => ContT r m r -> ContT r' m r
- reset :: Cont r r -> Cont r' r
- liftLocal :: Monad m => m r' -> ((r' -> r') -> m r -> m r) -> (r' -> r') -> ContT r m a -> ContT r m a
- evalContT :: Monad m => ContT r m r -> m r
- evalCont :: Cont r r -> r
Documentation
class Monad m => MonadIO (m :: Type -> Type) where #
Monads in which IO computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
Methods
Lift a computation from the IO monad.
This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations
(i.e. IO is the base monad for the stack).
Example
import Control.Monad.Trans.State -- from the "transformers" library printState :: Show s => StateT s IO () printState = do state <- get liftIO $ print state
Had we omitted , we would have ended up with this error:liftIO
• Couldn't match type ‘IO’ with ‘StateT s IO’ Expected type: StateT s IO () Actual type: IO ()
The important part here is the mismatch between StateT s IO () and .IO ()
Luckily, we know of a function that takes an and returns an IO a(m a): ,
enabling us to run the program and see the expected results:liftIO
> evalStateT printState "hello" "hello" > evalStateT printState 3 3
Instances
| MonadIO IO | Since: base-4.9.0.0 |
Defined in Control.Monad.IO.Class | |
| MonadIO m => MonadIO (MaybeT m) | |
Defined in Control.Monad.Trans.Maybe | |
| (Error e, MonadIO m) => MonadIO (ErrorT e m) | |
Defined in Control.Monad.Trans.Error | |
| MonadIO m => MonadIO (ExceptT e m) | |
Defined in Control.Monad.Trans.Except | |
| MonadIO m => MonadIO (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
| MonadIO m => MonadIO (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
| (Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Strict | |
| MonadIO m => MonadIO (ContT r m) | |
Defined in Control.Monad.Trans.Cont | |
| (Monoid w, MonadIO m) => MonadIO (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Strict | |
Identity functor and monad. (a non-strict monad)
Since: base-4.8.0.0
Constructors
| Identity | |
Fields
| |
Instances
class MonadTrans (t :: (Type -> Type) -> Type -> Type) where #
The class of monad transformers. Instances should satisfy the
following laws, which state that lift is a monad transformation:
Methods
lift :: Monad m => m a -> t m a #
Lift a computation from the argument monad to the constructed monad.
Instances
| MonadTrans MaybeT | |
Defined in Control.Monad.Trans.Maybe | |
| MonadTrans (ErrorT e) | |
Defined in Control.Monad.Trans.Error | |
| MonadTrans (ExceptT e) | |
Defined in Control.Monad.Trans.Except | |
| MonadTrans (ReaderT r) | |
Defined in Control.Monad.Trans.Reader | |
| MonadTrans (StateT s) | |
Defined in Control.Monad.Trans.State.Strict | |
| Monoid w => MonadTrans (WriterT w) | |
Defined in Control.Monad.Trans.Writer.Strict | |
| MonadTrans (ContT r) | |
Defined in Control.Monad.Trans.Cont | |
| Monoid w => MonadTrans (RWST r w s) | |
Defined in Control.Monad.Trans.RWS.Strict | |
class (Monoid w, MonadReader r m, MonadWriter w m, MonadState s m) => MonadRWS r w s (m :: Type -> Type) | m -> r, m -> w, m -> s #
Instances
| MonadRWS r w s m => MonadRWS r w s (MaybeT m) | |
Defined in Control.Monad.RWS.Class | |
| (Error e, MonadRWS r w s m) => MonadRWS r w s (ErrorT e m) | |
Defined in Control.Monad.RWS.Class | |
| MonadRWS r w s m => MonadRWS r w s (ExceptT e m) | Since: mtl-2.2 |
Defined in Control.Monad.RWS.Class | |
| MonadRWS r w s m => MonadRWS r w s (IdentityT m) | |
Defined in Control.Monad.RWS.Class | |
| (Monoid w, Monad m) => MonadRWS r w s (RWST r w s m) | |
Defined in Control.Monad.RWS.Class | |
| (Monoid w, Monad m) => MonadRWS r w s (RWST r w s m) | |
Defined in Control.Monad.RWS.Class | |
class (Monoid w, Monad m) => MonadWriter w (m :: Type -> Type) | m -> w where #
Methods
embeds a simple writer action.writer (a,w)
is an action that produces the output tell ww.
is an action that executes the action listen mm and adds
its output to the value of the computation.
pass :: m (a, w -> w) -> m a #
is an action that executes the action pass mm, which
returns a value and a function, and returns the value, applying
the function to the output.
Instances
| MonadWriter w m => MonadWriter w (MaybeT m) | |
| Monoid w => MonadWriter w ((,) w) | NOTE: This instance is only defined for Since: mtl-2.2.2 |
| (Error e, MonadWriter w m) => MonadWriter w (ErrorT e m) | |
| MonadWriter w m => MonadWriter w (ExceptT e m) | Since: mtl-2.2 |
| MonadWriter w m => MonadWriter w (IdentityT m) | |
| MonadWriter w m => MonadWriter w (ReaderT r m) | |
| MonadWriter w m => MonadWriter w (StateT s m) | |
| MonadWriter w m => MonadWriter w (StateT s m) | |
| (Monoid w, Monad m) => MonadWriter w (WriterT w m) | |
| (Monoid w, Monad m) => MonadWriter w (WriterT w m) | |
| (Monoid w, Monad m) => MonadWriter w (RWST r w s m) | |
| (Monoid w, Monad m) => MonadWriter w (RWST r w s m) | |
listens :: MonadWriter w m => (w -> b) -> m a -> m (a, b) #
censor :: MonadWriter w m => (w -> w) -> m a -> m a #
class Monad m => MonadState s (m :: Type -> Type) | m -> s where #
Minimal definition is either both of get and put or just state
Methods
Return the state from the internals of the monad.
Replace the state inside the monad.
state :: (s -> (a, s)) -> m a #
Embed a simple state action into the monad.
Instances
| MonadState s m => MonadState s (ListT m) | |
| MonadState s m => MonadState s (MaybeT m) | |
| (Error e, MonadState s m) => MonadState s (ErrorT e m) | |
| MonadState s m => MonadState s (ExceptT e m) | Since: mtl-2.2 |
| MonadState s m => MonadState s (IdentityT m) | |
| MonadState s m => MonadState s (ReaderT r m) | |
| Monad m => MonadState s (StateT s m) | |
| Monad m => MonadState s (StateT s m) | |
| (Monoid w, MonadState s m) => MonadState s (WriterT w m) | |
| (Monoid w, MonadState s m) => MonadState s (WriterT w m) | |
| MonadState s m => MonadState s (ContT r m) | |
| (Monad m, Monoid w) => MonadState s (RWST r w s m) | |
| (Monad m, Monoid w) => MonadState s (RWST r w s m) | |
modify' :: MonadState s m => (s -> s) -> m () #
A variant of modify in which the computation is strict in the
new state.
Since: mtl-2.2
modify :: MonadState s m => (s -> s) -> m () #
Monadic state transformer.
Maps an old state to a new state inside a state monad. The old state is thrown away.
Main> :t modify ((+1) :: Int -> Int)
modify (...) :: (MonadState Int a) => a ()This says that modify (+1) acts over any
Monad that is a member of the MonadState class,
with an Int state.
gets :: MonadState s m => (s -> a) -> m a #
Gets specific component of the state, using a projection function supplied.
class Monad m => MonadReader r (m :: Type -> Type) | m -> r where #
See examples in Control.Monad.Reader.
Note, the partially applied function type (->) r is a simple reader monad.
See the instance declaration below.
Methods
Retrieves the monad environment.
Arguments
| :: (r -> r) | The function to modify the environment. |
| -> m a |
|
| -> m a |
Executes a computation in a modified environment.
Arguments
| :: (r -> a) | The selector function to apply to the environment. |
| -> m a |
Retrieves a function of the current environment.
Instances
| MonadReader r m => MonadReader r (ListT m) | |
| MonadReader r m => MonadReader r (MaybeT m) | |
| (Error e, MonadReader r m) => MonadReader r (ErrorT e m) | |
| MonadReader r m => MonadReader r (ExceptT e m) | Since: mtl-2.2 |
| MonadReader r m => MonadReader r (IdentityT m) | |
| Monad m => MonadReader r (ReaderT r m) | |
| MonadReader r m => MonadReader r (StateT s m) | |
| MonadReader r m => MonadReader r (StateT s m) | |
| (Monoid w, MonadReader r m) => MonadReader r (WriterT w m) | |
| (Monoid w, MonadReader r m) => MonadReader r (WriterT w m) | |
| MonadReader r ((->) r) | |
| MonadReader r' m => MonadReader r' (ContT r m) | |
| (Monad m, Monoid w) => MonadReader r (RWST r w s m) | |
| (Monad m, Monoid w) => MonadReader r (RWST r w s m) | |
Arguments
| :: MonadReader r m | |
| => (r -> a) | The selector function to apply to the environment. |
| -> m a |
Retrieves a function of the current environment.
class Monad m => MonadError e (m :: Type -> Type) | m -> e where #
The strategy of combining computations that can throw exceptions by bypassing bound functions from the point an exception is thrown to the point that it is handled.
Is parameterized over the type of error information and
the monad type constructor.
It is common to use as the monad type constructor
for an error monad in which error descriptions take the form of strings.
In that case and many other common cases the resulting monad is already defined
as an instance of the Either StringMonadError class.
You can also define your own error type and/or use a monad type constructor
other than or Either String.
In these cases you will have to explicitly define instances of the Either IOErrorMonadError
class.
(If you are using the deprecated Control.Monad.Error or
Control.Monad.Trans.Error, you may also have to define an Error instance.)
Methods
throwError :: e -> m a #
Is used within a monadic computation to begin exception processing.
catchError :: m a -> (e -> m a) -> m a #
A handler function to handle previous errors and return to normal execution. A common idiom is:
do { action1; action2; action3 } `catchError` handlerwhere the action functions can call throwError.
Note that handler and the do-block must have the same return type.
Instances
liftEither :: MonadError e m => Either e a -> m a #
Lifts an into any Either e.MonadError e
do { val <- liftEither =<< action1; action2 }where action1 returns an Either to represent errors.
Since: mtl-2.2.2
class Monad m => MonadCont (m :: Type -> Type) where #
Methods
callCC :: ((a -> m b) -> m a) -> m a #
callCC (call-with-current-continuation)
calls a function with the current continuation as its argument.
Provides an escape continuation mechanism for use with Continuation monads.
Escape continuations allow to abort the current computation and return
a value immediately.
They achieve a similar effect to throwError
and catchError
within an Error monad.
Advantage of this function over calling return is that it makes
the continuation explicit,
allowing more flexibility and better control
(see examples in Control.Monad.Cont).
The standard idiom used with callCC is to provide a lambda-expression
to name the continuation. Then calling the named continuation anywhere
within its scope will escape from the computation,
even if it is many layers deep within nested computations.
Instances
| MonadCont m => MonadCont (ListT m) | |
| MonadCont m => MonadCont (MaybeT m) | |
| (Error e, MonadCont m) => MonadCont (ErrorT e m) | |
| MonadCont m => MonadCont (ExceptT e m) | Since: mtl-2.2 |
| MonadCont m => MonadCont (IdentityT m) | |
| MonadCont m => MonadCont (ReaderT r m) | |
| MonadCont m => MonadCont (StateT s m) | |
| MonadCont m => MonadCont (StateT s m) | |
| (Monoid w, MonadCont m) => MonadCont (WriterT w m) | |
| (Monoid w, MonadCont m) => MonadCont (WriterT w m) | |
| MonadCont (ContT r m) | |
| (Monoid w, MonadCont m) => MonadCont (RWST r w s m) | |
| (Monoid w, MonadCont m) => MonadCont (RWST r w s m) | |
cont :: ((a -> r) -> r) -> Cont r a #
Construct a continuation-passing computation from a function.
(The inverse of runCont)
Arguments
| :: Cont r a | continuation computation ( |
| -> (a -> r) | the final continuation, which produces
the final result (often |
| -> r |
The result of running a CPS computation with a given final continuation.
(The inverse of cont)
type Cont r = ContT r Identity #
Continuation monad.
Cont r a is a CPS ("continuation-passing style") computation that produces an
intermediate result of type a within a CPS computation whose final result type
is r.
The return function simply creates a continuation which passes the value on.
The >>= operator adds the bound function into the continuation chain.
newtype ContT (r :: k) (m :: k -> Type) a #
The continuation monad transformer.
Can be used to add continuation handling to any type constructor:
the Monad instance and most of the operations do not require m
to be a monad.
ContT is not a functor on the category of monads, and many operations
cannot be lifted through it.
Instances
| MonadReader r' m => MonadReader r' (ContT r m) | |
| MonadState s m => MonadState s (ContT r m) | |
| MonadTrans (ContT r) | |
Defined in Control.Monad.Trans.Cont | |
| MonadFail m => MonadFail (ContT r m) | |
Defined in Control.Monad.Trans.Cont | |
| MonadIO m => MonadIO (ContT r m) | |
Defined in Control.Monad.Trans.Cont | |
| Applicative (ContT r m) | |
Defined in Control.Monad.Trans.Cont | |
| Functor (ContT r m) | |
| Monad (ContT r m) | |
| MonadCont (ContT r m) | |
Minimal complete definition
Nothing
Methods
Creates an exception without a message.
The default implementation is .strMsg ""
Instances
| Error IOException | |
Defined in Control.Monad.Trans.Error | |
| ErrorList a => Error [a] | A string can be thrown as an error. |
mapExceptT :: (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b #
Map the unwrapped computation using the given function.
runExceptT(mapExceptTf m) = f (runExceptTm)
runExcept :: Except e a -> Either e a #
Extractor for computations in the exception monad.
(The inverse of except).
runExceptT :: ExceptT e m a -> m (Either e a) #
The inverse of ExceptT.
withExcept :: (e -> e') -> Except e a -> Except e' a #
Transform any exceptions thrown by the computation using the given
function (a specialization of withExceptT).
withExceptT :: forall (m :: Type -> Type) e e' a. Functor m => (e -> e') -> ExceptT e m a -> ExceptT e' m a #
Transform any exceptions thrown by the computation using the given function.
newtype ExceptT e (m :: Type -> Type) a #
A monad transformer that adds exceptions to other monads.
ExceptT constructs a monad parameterized over two things:
- e - The exception type.
- m - The inner monad.
The return function yields a computation that produces the given
value, while >>= sequences two subcomputations, exiting on the
first exception.
Instances
Arguments
| :: RWS r w s a | RWS computation to execute |
| -> r | initial environment |
| -> s | initial value |
| -> (a, w) | final value and output |
Evaluate a computation with the given initial state and environment, returning the final value and output, discarding the final state.
Arguments
| :: Monad m | |
| => RWST r w s m a | computation to execute |
| -> r | initial environment |
| -> s | initial value |
| -> m (a, w) | computation yielding final value and output |
Evaluate a computation with the given initial state and environment, returning the final value and output, discarding the final state.
Arguments
| :: RWS r w s a | RWS computation to execute |
| -> r | initial environment |
| -> s | initial value |
| -> (s, w) | final state and output |
Evaluate a computation with the given initial state and environment, returning the final state and output, discarding the final value.
Arguments
| :: Monad m | |
| => RWST r w s m a | computation to execute |
| -> r | initial environment |
| -> s | initial value |
| -> m (s, w) | computation yielding final state and output |
Evaluate a computation with the given initial state and environment, returning the final state and output, discarding the final value.
runRWS :: RWS r w s a -> r -> s -> (a, s, w) #
Unwrap an RWS computation as a function.
(The inverse of rws.)
rws :: (r -> s -> (a, s, w)) -> RWS r w s a #
Construct an RWS computation from a function.
(The inverse of runRWS.)
withRWST :: forall r' s r w (m :: Type -> Type) a. (r' -> s -> (r, s)) -> RWST r w s m a -> RWST r' w s m a #
type RWS r w s = RWST r w s Identity #
A monad containing an environment of type r, output of type w
and an updatable state of type s.
newtype RWST r w s (m :: Type -> Type) a #
A monad transformer adding reading an environment of type r,
collecting an output of type w and updating a state of type s
to an inner monad m.
Instances
mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b #
Transform the computation inside a ReaderT.
runReaderT(mapReaderTf m) = f .runReaderTm
Arguments
| :: Reader r a | A |
| -> r | An initial environment. |
| -> a |
Runs a Reader and extracts the final value from it.
(The inverse of reader.)
Arguments
| :: (r' -> r) | The function to modify the environment. |
| -> Reader r a | Computation to run in the modified environment. |
| -> Reader r' a |
Execute a computation in a modified environment
(a specialization of withReaderT).
runReader(withReaderf m) =runReaderm . f
Arguments
| :: forall r' r (m :: Type -> Type) a. (r' -> r) | The function to modify the environment. |
| -> ReaderT r m a | Computation to run in the modified environment. |
| -> ReaderT r' m a |
Execute a computation in a modified environment
(a more general version of local).
runReaderT(withReaderTf m) =runReaderTm . f
type Reader r = ReaderT r Identity #
The parameterizable reader monad.
Computations are functions of a shared environment.
The return function ignores the environment, while >>= passes
the inherited environment to both subcomputations.
newtype ReaderT r (m :: Type -> Type) a #
The reader monad transformer, which adds a read-only environment to the given monad.
The return function ignores the environment, while >>= passes
the inherited environment to both subcomputations.
Constructors
| ReaderT | |
Fields
| |
Instances
| MonadError e m => MonadError e (ReaderT r m) | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> ReaderT r m a # catchError :: ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a # | |
| Monad m => MonadReader r (ReaderT r m) | |
| MonadState s m => MonadState s (ReaderT r m) | |
| MonadWriter w m => MonadWriter w (ReaderT r m) | |
| MonadTrans (ReaderT r) | |
Defined in Control.Monad.Trans.Reader | |
| MonadFail m => MonadFail (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
| MonadFix m => MonadFix (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
| MonadIO m => MonadIO (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
| MonadZip m => MonadZip (ReaderT r m) | |
| Contravariant m => Contravariant (ReaderT r m) | |
| Alternative m => Alternative (ReaderT r m) | |
| Applicative m => Applicative (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
| Functor m => Functor (ReaderT r m) | |
| Monad m => Monad (ReaderT r m) | |
| MonadPlus m => MonadPlus (ReaderT r m) | |
| MonadCont m => MonadCont (ReaderT r m) | |
Arguments
| :: State s a | state-passing computation to execute |
| -> s | initial value |
| -> a | return value of the state computation |
evalStateT :: Monad m => StateT s m a -> s -> m a #
Evaluate a state computation with the given initial state and return the final value, discarding the final state.
evalStateTm s =liftMfst(runStateTm s)
Arguments
| :: State s a | state-passing computation to execute |
| -> s | initial value |
| -> s | final state |
execStateT :: Monad m => StateT s m a -> s -> m s #
Evaluate a state computation with the given initial state and return the final state, discarding the final value.
execStateTm s =liftMsnd(runStateTm s)
Arguments
| :: State s a | state-passing computation to execute |
| -> s | initial state |
| -> (a, s) | return value and final state |
Unwrap a state monad computation as a function.
(The inverse of state.)
withStateT :: forall s (m :: Type -> Type) a. (s -> s) -> StateT s m a -> StateT s m a #
executes action withStateT f mm on a state modified by
applying f.
withStateTf m =modifyf >> m
type State s = StateT s Identity #
A state monad parameterized by the type s of the state to carry.
The return function leaves the state unchanged, while >>= uses
the final state of the first computation as the initial state of
the second.
newtype StateT s (m :: Type -> Type) a #
A state transformer monad parameterized by:
s- The state.m- The inner monad.
The return function leaves the state unchanged, while >>= uses
the final state of the first computation as the initial state of
the second.
Instances
| MonadError e m => MonadError e (StateT s m) | |
Defined in Control.Monad.Error.Class Methods throwError :: e -> StateT s m a # catchError :: StateT s m a -> (e -> StateT s m a) -> StateT s m a # | |
| MonadReader r m => MonadReader r (StateT s m) | |
| Monad m => MonadState s (StateT s m) | |
| MonadWriter w m => MonadWriter w (StateT s m) | |
| MonadTrans (StateT s) | |
Defined in Control.Monad.Trans.State.Strict | |
| MonadFail m => MonadFail (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
| MonadFix m => MonadFix (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
| MonadIO m => MonadIO (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
| Contravariant m => Contravariant (StateT s m) | |
| (Functor m, MonadPlus m) => Alternative (StateT s m) | |
| (Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
| Functor m => Functor (StateT s m) | |
| Monad m => Monad (StateT s m) | |
| MonadPlus m => MonadPlus (StateT s m) | |
| MonadCont m => MonadCont (StateT s m) | |
execWriter :: Writer w a -> w #
Extract the output from a writer computation.
execWriterm =snd(runWriterm)
execWriterT :: Monad m => WriterT w m a -> m w #
Extract the output from a writer computation.
execWriterTm =liftMsnd(runWriterTm)
mapWriterT :: (m (a, w) -> n (b, w')) -> WriterT w m a -> WriterT w' n b #
Map both the return value and output of a computation using the given function.
runWriterT(mapWriterTf m) = f (runWriterTm)
runWriter :: Writer w a -> (a, w) #
Unwrap a writer computation as a (result, output) pair.
(The inverse of writer.)
newtype WriterT w (m :: Type -> Type) a #
A writer monad parameterized by:
w- the output to accumulate.m- The inner monad.
The return function produces the output mempty, while >>=
combines the outputs of the subcomputations using mappend.
Constructors
| WriterT | |
Fields
| |
Instances
newtype MaybeT (m :: Type -> Type) a #
The parameterizable maybe monad, obtained by composing an arbitrary
monad with the Maybe monad.
Computations are actions that may produce a value or exit.
The return function yields a computation that produces that
value, while >>= sequences two subcomputations, exiting if either
computation does.
Instances
liftPass :: Monad m => Pass w m (Maybe a) -> Pass w (MaybeT m) a #
Lift a pass operation to the new monad.
liftListen :: Monad m => Listen w m (Maybe a) -> Listen w (MaybeT m) a #
Lift a listen operation to the new monad.
liftCallCC :: CallCC m (Maybe a) (Maybe b) -> CallCC (MaybeT m) a b #
Lift a callCC operation to the new monad.
except :: forall (m :: Type -> Type) e a. Monad m => Either e a -> ExceptT e m a #
Constructor for computations in the exception monad.
(The inverse of runExcept).
liftLocal :: Monad m => m r' -> ((r' -> r') -> m r -> m r) -> (r' -> r') -> ContT r m a -> ContT r m a #