Safe Haskell | None |
---|---|
Language | Haskell2010 |
This package provides DepT
, a monad transformer similar to ReaderT
.
The difference is that the environment of DepT
must be parameterized by
DepT
's own monad stack.
There's a function withDepT
which is analogous to withReaderT
.
There's no analogue of mapReaderT
however. This means you can't tweak
the monad below the DepT
with a natural transformation.
Synopsis
- newtype DepT env m r = DepT (ReaderT (env (DepT env m)) m r)
- runDepT :: DepT env m r -> env (DepT env m) -> m r
- toReaderT :: DepT env m r -> ReaderT (env (DepT env m)) m r
- withDepT :: forall small big m a. Monad m => (forall p q. (forall x. p x -> q x) -> small p -> small q) -> (forall t. big t -> small t) -> DepT small m a -> DepT big m a
- zoomEnv :: forall small big m a. Monad m => (forall p q. (forall x. p x -> q x) -> small p -> small q) -> (forall t. big t -> small t) -> small (DepT small m) -> small (DepT big m)
- data NilEnv m = NilEnv
Documentation
A monad transformer which adds a read-only environment to the given monad. The environment type must be parameterized with the transformer's stack.
The return
function ignores the environment, while >>=
passes the
inherited environment to both subcomputations.
Instances
:: forall small big m a. Monad m | |
=> (forall p q. (forall x. p x -> q x) -> small p -> small q) | rank-2 map function |
-> (forall t. big t -> small t) | get a small environment from a big one |
-> DepT small m a | |
-> DepT big m a |
Changes the environment of a DepT
, for example making the DepT
work in
a "bigger" environment than the one in which was defined initially.
The scary first parameter is a function that, given a natural transformation of monads, changes the monad parameter of the environment record. This function can be defined manually for each environment record, or it can be generated using TH from the "rank2classes" package.
:: forall small big m a. Monad m | |
=> (forall p q. (forall x. p x -> q x) -> small p -> small q) | rank-2 map function |
-> (forall t. big t -> small t) | get a small environment from a big one |
-> small (DepT small m) | |
-> small (DepT big m) |
Makes the functions inside a small environment require a bigger environment.
This can be useful if we are encasing the small environment as a field of the big environment, in order to make the types match.
The scary first parameter is a function that, given a natural transformation of monads, changes the monad parameter of the environment record. This function can be defined manually for each environment record, or it can be generated using TH from the "rank2classes" package.