Stability | experimental |
---|---|
Maintainer | Ertugrul Soeylemez <es@ertes.de> |
This module implements a number of monad transformers using a CPS approach internally.
- newtype Id a = Id {
- getId :: a
- newtype IdT m a = IdT {
- getIdT :: m a
- newtype ContT r m a = ContT {
- getContT :: (a -> m r) -> m r
- runContT :: (a -> m r) -> ContT r m a -> m r
- evalContT :: Applicative m => ContT r m r -> m r
- modifyContT :: Functor m => (r -> r) -> ContT r m ()
- newtype ChoiceT r i m a = ChoiceT {
- getChoiceT :: (i -> a -> (i -> m r) -> m r) -> i -> (i -> m r) -> m r
- runChoiceT :: (i -> a -> (i -> m r) -> m r) -> i -> (i -> m r) -> ChoiceT r i m a -> m r
- choice :: [a] -> ChoiceT r i m a
- findAll :: (Alternative f, Applicative m) => ChoiceT (f a) (f a) m a -> m (f a)
- findAll_ :: Applicative m => ChoiceT () i m a -> m ()
- findFirst :: (Alternative f, Applicative m) => ChoiceT (f a) (f a) m a -> m (f a)
- findFirst_ :: Applicative m => ChoiceT () i m a -> m ()
- listA :: Alternative f => [a] -> f a
- listChoiceT :: Applicative m => ChoiceT [a] [a] m a -> m [a]
- maybeChoiceT :: Applicative m => ChoiceT (Maybe a) (Maybe a) m a -> m (Maybe a)
- newtype EitherT r e m a = EitherT {
- getEitherT :: (a -> m r) -> (e -> m r) -> m r
- runEitherT :: (a -> m r) -> (e -> m r) -> EitherT r e m a -> m r
- evalEitherT :: Applicative m => EitherT (Either e a) e m a -> m (Either e a)
- modifyEitherT :: Functor m => (r -> r) -> EitherT r e m ()
- newtype MaybeT r m a = MaybeT {
- getMaybeT :: (a -> m r) -> m r -> m r
- runMaybeT :: (a -> m r) -> m r -> MaybeT r m a -> m r
- evalMaybeT :: Applicative m => MaybeT (Maybe a) m a -> m (Maybe a)
- modifyMaybeT :: Functor m => (r -> r) -> MaybeT r m ()
- newtype StateT r s m a = StateT {
- getStateT :: s -> (s -> a -> m r) -> m r
- runStateT :: s -> (s -> a -> m r) -> StateT r s m a -> m r
- evalStateT :: Applicative m => s -> StateT r s m r -> m r
- execStateT :: Applicative m => s -> StateT s s m a -> m s
- type WriterT = ContT
- runWriterT :: Alternative m => WriterT r m a -> m r
- type OldWriterT r w m a = ContT (r, w) m a
- runOldWriterT :: (Applicative m, Monoid w) => OldWriterT r w m r -> m (r, w)
- evalOldWriterT :: (Applicative m, Monoid w) => OldWriterT r w m r -> m r
- execOldWriterT :: (Applicative m, Monoid w) => OldWriterT r w m r -> m w
The identity monad
The identity monad. This monad represents values themselves, i.e. computations without effects.
Monad transformers
Identity transformer
The identity monad transformer. This monad transformer represents computations themselves without further side effects. Unlike most other monad transformers in this module it is not implemented in terms of continuation passing style.
Transformer IdT | |
Runnable IdT r m r | |
Monad m => Monad (IdT m) | |
Functor m => Functor (IdT m) | |
MonadFix m => MonadFix (IdT m) | |
(Alternative m, Monad m) => MonadPlus (IdT m) | |
Applicative m => Applicative (IdT m) | |
Alternative m => Alternative (IdT m) | |
(Monad m, Stateful m) => Stateful (IdT m) | |
(LiftBase m, Monad m) => LiftBase (IdT m) |
ContT
The continuation passing style monad transformer. This monad transformer models the most basic form of CPS.
Transformer (ContT r) | |
Runnable (ContT r) r m a | |
Monad (ContT r m) | |
Functor (ContT r m) | |
Alternative m => MonadPlus (ContT r m) | |
Applicative (ContT r m) | |
Alternative m => Alternative (ContT r m) | |
(Monad m, Stateful m) => Stateful (ContT r m) | |
(LiftBase m, Monad m) => LiftBase (ContT r m) | |
CallCC (ContT r m) | |
Applicative m => Abortable (ContT r m) | |
(Functor m, Monoid w) => Writable (ContT (r, w) m) w | |
Alternative m => Writable (ContT r m) r |
runContT :: (a -> m r) -> ContT r m a -> m rSource
Run a CPS-style computation given the supplied final continuation.
evalContT :: Applicative m => ContT r m r -> m rSource
Evaluate a CPS-style computation to its final result.
modifyContT :: Functor m => (r -> r) -> ContT r m ()Source
Transform the final result along the way.
Choice/nondeterminism
newtype ChoiceT r i m a Source
The choice monad transformer, which models, as the most common interpretation, nondeterminism. Internally a list of choices is represented as a CPS-based left-fold function.
ChoiceT | |
|
runChoiceT :: (i -> a -> (i -> m r) -> m r) -> i -> (i -> m r) -> ChoiceT r i m a -> m rSource
Run a choice computation.
findAll :: (Alternative f, Applicative m) => ChoiceT (f a) (f a) m a -> m (f a)Source
Find all solutions.
findFirst :: (Alternative f, Applicative m) => ChoiceT (f a) (f a) m a -> m (f a)Source
Find the first solution.
findFirst_ :: Applicative m => ChoiceT () i m a -> m ()Source
Find the first solution and ignore it.
listA :: Alternative f => [a] -> f aSource
Turn a list into a computation with alternatives.
listChoiceT :: Applicative m => ChoiceT [a] [a] m a -> m [a]Source
Get list of solutions (faster than findAll
, but returns solutions
in reversed order).
maybeChoiceT :: Applicative m => ChoiceT (Maybe a) (Maybe a) m a -> m (Maybe a)Source
Get one solution (faster than findFirst
).
Exceptions
newtype EitherT r e m a Source
Monad transformer for CPS computations with an additional exception continuation.
EitherT | |
|
Transformer (EitherT r e) | |
Runnable (EitherT r e) r m a | |
Monad (EitherT r e m) | |
Functor (EitherT r e m) | |
Alternative m => MonadPlus (EitherT r e m) | |
Applicative (EitherT r e m) | |
Alternative m => Alternative (EitherT r e m) | |
(Monad m, Stateful m) => Stateful (EitherT r e m) | |
(LiftBase m, Monad m) => LiftBase (EitherT r e m) | |
HasExceptions (EitherT r e m) | |
CallCC (EitherT r e m) | |
Applicative m => Abortable (EitherT r e m) | |
(Functor m, Monoid w) => Writable (EitherT (r, w) e m) w | |
Alternative m => Writable (EitherT r e m) r |
runEitherT :: (a -> m r) -> (e -> m r) -> EitherT r e m a -> m rSource
Run an EitherT
transformer.
evalEitherT :: Applicative m => EitherT (Either e a) e m a -> m (Either e a)Source
modifyEitherT :: Functor m => (r -> r) -> EitherT r e m ()Source
Modify the result of an EitherT
computation along the way.
Monad transformer for CPS computations with an additional exception continuation with no argument.
Transformer (MaybeT r) | |
Runnable (MaybeT r) r m a | |
Monad (MaybeT r m) | |
Functor (MaybeT r m) | |
Alternative m => MonadPlus (MaybeT r m) | |
Applicative (MaybeT r m) | |
Alternative (MaybeT r m) | |
(Monad m, Stateful m) => Stateful (MaybeT r m) | |
(LiftBase m, Monad m) => LiftBase (MaybeT r m) | |
HasExceptions (MaybeT r m) | |
CallCC (MaybeT r m) | |
Applicative m => Abortable (MaybeT r m) | |
(Functor m, Monoid w) => Writable (MaybeT (r, w) m) w | |
Alternative m => Writable (MaybeT r m) r |
evalMaybeT :: Applicative m => MaybeT (Maybe a) m a -> m (Maybe a)Source
modifyMaybeT :: Functor m => (r -> r) -> MaybeT r m ()Source
Modify the result of a MaybeT
computation along the way.
State
Monad transformer for stateful computations.
Transformer (StateT r s) | |
Runnable (StateT r s) r m a | |
Monad (StateT r s m) | |
Functor (StateT r s m) | |
Alternative m => MonadPlus (StateT r s m) | |
Applicative (StateT r s m) | |
Alternative m => Alternative (StateT r s m) | |
Stateful (StateT r s m) | |
(LiftBase m, Monad m) => LiftBase (StateT r s m) | |
CallCC (StateT r s m) | |
Applicative m => Abortable (StateT r s m) | |
(Functor m, Monoid w) => Writable (StateT (r, w) s m) w | |
Alternative m => Writable (StateT r s m) r |
evalStateT :: Applicative m => s -> StateT r s m r -> m rSource
Run a state transformer returning its result.
execStateT :: Applicative m => s -> StateT s s m a -> m sSource
Run a state transformer returning its final state.
Writer monads
runWriterT :: Alternative m => WriterT r m a -> m rSource
Run a writer transformer.
type OldWriterT r w m a = ContT (r, w) m aSource
The traditional writer monad transformer.
runOldWriterT :: (Applicative m, Monoid w) => OldWriterT r w m r -> m (r, w)Source
Run a traditional writer transformer.
evalOldWriterT :: (Applicative m, Monoid w) => OldWriterT r w m r -> m rSource
Run a traditional writer transformer and return its result.
execOldWriterT :: (Applicative m, Monoid w) => OldWriterT r w m r -> m wSource
Run a traditional writer transformer and return its log.