dep-t-0.1.1.0: Reader-like monad transformer for dependency injection.
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Dep

Description

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

Documentation

newtype DepT env m r Source #

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.

Constructors

DepT (ReaderT (env (DepT env m)) m r) 

Instances

Instances details
MonadWriter w m => MonadWriter w (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

writer :: (a, w) -> DepT env m a #

tell :: w -> DepT env m () #

listen :: DepT env m a -> DepT env m (a, w) #

pass :: DepT env m (a, w -> w) -> DepT env m a #

MonadState s m => MonadState s (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

get :: DepT env m s #

put :: s -> DepT env m () #

state :: (s -> (a, s)) -> DepT env m a #

MonadError e m => MonadError e (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

throwError :: e -> DepT env m a #

catchError :: DepT env m a -> (e -> DepT env m a) -> DepT env m a #

MonadTrans (DepT env) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

lift :: Monad m => m a -> DepT env m a #

Monad m => MonadReader (env (DepT env m)) (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

ask :: DepT env m (env (DepT env m)) #

local :: (env (DepT env m) -> env (DepT env m)) -> DepT env m a -> DepT env m a #

reader :: (env (DepT env m) -> a) -> DepT env m a #

Monad m => Monad (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

(>>=) :: DepT env m a -> (a -> DepT env m b) -> DepT env m b #

(>>) :: DepT env m a -> DepT env m b -> DepT env m b #

return :: a -> DepT env m a #

Functor m => Functor (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

fmap :: (a -> b) -> DepT env m a -> DepT env m b #

(<$) :: a -> DepT env m b -> DepT env m a #

MonadFix m => MonadFix (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

mfix :: (a -> DepT env m a) -> DepT env m a #

MonadFail m => MonadFail (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

fail :: String -> DepT env m a #

Applicative m => Applicative (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

pure :: a -> DepT env m a #

(<*>) :: DepT env m (a -> b) -> DepT env m a -> DepT env m b #

liftA2 :: (a -> b -> c) -> DepT env m a -> DepT env m b -> DepT env m c #

(*>) :: DepT env m a -> DepT env m b -> DepT env m b #

(<*) :: DepT env m a -> DepT env m b -> DepT env m a #

MonadZip m => MonadZip (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

mzip :: DepT env m a -> DepT env m b -> DepT env m (a, b) #

mzipWith :: (a -> b -> c) -> DepT env m a -> DepT env m b -> DepT env m c #

munzip :: DepT env m (a, b) -> (DepT env m a, DepT env m b) #

MonadIO m => MonadIO (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

liftIO :: IO a -> DepT env m a #

Alternative m => Alternative (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

empty :: DepT env m a #

(<|>) :: DepT env m a -> DepT env m a -> DepT env m a #

some :: DepT env m a -> DepT env m [a] #

many :: DepT env m a -> DepT env m [a] #

MonadPlus m => MonadPlus (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

mzero :: DepT env m a #

mplus :: DepT env m a -> DepT env m a -> DepT env m a #

MonadCont m => MonadCont (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

callCC :: ((a -> DepT env m b) -> DepT env m a) -> DepT env m a #

MonadUnliftIO m => MonadUnliftIO (DepT env m) Source # 
Instance details

Defined in Control.Monad.Dep

Methods

withRunInIO :: ((forall a. DepT env m a -> IO a) -> IO b) -> DepT env m b #

runDepT :: DepT env m r -> env (DepT env m) -> m r Source #

Runs a DepT action in an environment.

toReaderT :: DepT env m r -> ReaderT (env (DepT env m)) m r Source #

withDepT Source #

Arguments

:: 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.

zoomEnv Source #

Arguments

:: 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.

data NilEnv m Source #

An empty environment that carries no functions, analogous to () for ReaderT.

Constructors

NilEnv