Safe Haskell | None |
---|---|
Language | Haskell98 |
The multi-valued version of mtl's Reader / ReaderT / MonadReader
- newtype MultiReaderT x m a = MultiReaderT {
- runMultiReaderTRaw :: StateT (HList x) m a
- type MultiReaderTNull = MultiReaderT Null
- type MultiReader x = MultiReaderT x Identity
- class Monad m => MonadMultiReader a m where
- mAsk :: m a
- mAskRaw :: Monad m => MultiReaderT a m (HList a)
- withMultiReader :: Monad m => x -> MultiReaderT (Cons x xs) m a -> MultiReaderT xs m a
- withMultiReaders :: Monad m => HList xs -> MultiReaderT (Append xs ys) m a -> MultiReaderT ys m a
- evalMultiReaderT :: Monad m => MultiReaderT Null m a -> m a
- evalMultiReaderTWithInitial :: Monad m => HList a -> MultiReaderT a m b -> m b
- mapMultiReaderT :: (m (a, HList w) -> m' (a', HList w)) -> MultiReaderT w m a -> MultiReaderT w m' a'
- data Cons car cdr :: * -> * -> *
- data Null :: *
MultiReaderT
newtype MultiReaderT x m a Source
A Reader transformer monad patameterized by:
- x - The list of types constituting the environment / input (to be read),
- m - The inner monad.
MultiReaderT
corresponds to mtl's ReaderT
, but can contain
a heterogenous list of types.
This heterogenous list is represented using Types.Data.List, i.e:
For example,
MultiReaderT (Cons Int (Cons Bool Null)) :: (* -> *) -> (* -> *)
is a Reader wrapper containing the types [Int,Bool].
MultiReaderT | |
|
MonadState s m => MonadState s (MultiReaderT c m) | |
MonadWriter w m => MonadWriter w (MultiReaderT c m) | |
(Monad m, ContainsType a c) => MonadMultiReader a (MultiReaderT c m) | |
MonadTrans (MultiReaderT x) | |
Monad m => Monad (MultiReaderT x m) | |
Functor f => Functor (MultiReaderT x f) | |
(Applicative m, Monad m) => Applicative (MultiReaderT x m) |
type MultiReaderTNull = MultiReaderT Null Source
A MultiReader transformer carrying an empty state.
type MultiReader x = MultiReaderT x Identity Source
A reader monad parameterized by the list of types x of the environment / input to carry.
Similar to Reader r = ReaderT r Identity
MonadMultiReader class
class Monad m => MonadMultiReader a m where Source
All methods must be defined.
The idea is: Any monad stack is instance of MonadMultiReader a
, iff
the stack contains a MultiReaderT x
with a element of x.
(MonadTrans t, Monad (t m), MonadMultiReader a m) => MonadMultiReader a (t m) | |
(Monad m, ContainsType a c) => MonadMultiReader a (MultiReaderT c m) |
functions
mAskRaw :: Monad m => MultiReaderT a m (HList a) Source
A raw extractor of the contained HList (i.e. the complete environment).
For a possible usecase, see withMultiReaders
.
withMultiReader :: Monad m => x -> MultiReaderT (Cons x xs) m a -> MultiReaderT xs m a Source
Adds an element to the environment, thereby transforming a MultiReaderT carrying an environment with types (x:xs) to a a MultiReaderT with xs.
Think "Execute this computation with this additional value as environment".
withMultiReaders :: Monad m => HList xs -> MultiReaderT (Append xs ys) m a -> MultiReaderT ys m a Source
Adds a heterogenous list of elements to the environment, thereby transforming a MultiReaderT carrying an environment with values over types xs++ys to a MultiReaderT over ys.
Similar to recursively adding single values with withMultiReader
.
Note that ys can be Null; in that case the return value can be
evaluated further using evalMultiReaderT
.
evalMultiReaderT :: Monad m => MultiReaderT Null m a -> m a Source
Evaluate a computation over an empty environment.
Because the environment is empty, it does not need to be provided.
If you want to evaluate a computation over any non-Null environment, either use
evalMultiReaderTWithInitial
- simplify the computation using
withMultiReader
/withMultiReaders
, then useevalMultiReaderT
on the result.
evalMultiReaderTWithInitial Source
:: Monad m | |
=> HList a | The initial state |
-> MultiReaderT a m b | The computation to evaluate |
-> m b |
Evaluate a reader computation with the given environment.
mapMultiReaderT :: (m (a, HList w) -> m' (a', HList w)) -> MultiReaderT w m a -> MultiReaderT w m' a' Source
Map both the return value and the environment of a computation using the given function.
Note that there is a difference to mtl's ReaderT, where it is not possible to modify the environment.
re-exports
data Cons car cdr :: * -> * -> *
(Show a, Show (HList b)) => Show (HList (Cons a b)) | |
(Monoid x, Monoid (HList xs)) => Monoid (HList (Cons x xs)) | |
(Show car, Show cdr) => Show (Cons car cdr) | |
Typeable (* -> * -> *) Cons | |
type IsNull (Cons car cdr) = False | |
type Head (Cons car cdr) = car | |
type Tail (Cons car cdr) = cdr | |
type Reverse' (Cons car cdr) a = Reverse' cdr (Cons car a) | |
type Append (Cons car1 cdr2) l2 = Cons car1 (Append cdr2 l2) |