transformers-compose-0.1: Arrow-like / category-like composition for transformers.

Portabilityportable
Stabilityexperimental

Control.Monad.Compose.Class

Description

This module provides Arrow-like monad composition for transformers. To be more precise, it is Category-like, i.e. the parallels are to Control.Category.Category.

This version has been adapted from monadLib-compose, to work with the transformers package.

Control.Category.Category generalises . and id to arrows and categories. One such arrow is Kleisli, which represents functions returning monadic values. Incidentally, that's equivalent to ReaderT! So it turns out that it is possible to generalise . and id to ReaderT (id is just ask), as well as to many monad transformer stacks that embed a ReaderT inside.

Synopsis

Documentation

class (Monad m, Monad n) => MonadCompose m n s t | m -> s, n -> t, n s -> m whereSource

Composable monads. Compare with Control.Category.Category. Note that there are two different monad types involved in each instance.

Methods

mcompose :: m a -> n s -> n aSource

Compose two monadic values from right to left. mcompose f g is comparable to f . g but for monadic values. Compare with Control.Category...

mapply :: m a -> s -> n aSource

Apply a constant value to a composable monad.

Instances

MonadCompose ((->) s) ((->) t) s t 
MonadCompose m n s t => MonadCompose (MaybeT m) (MaybeT n) s t 
MonadCompose m n s t => MonadCompose (IdentityT m) (IdentityT n) s t 
(MonadCompose m n s t, Monoid w) => MonadCompose (WriterT w m) (WriterT w n) s t 
(MonadCompose m n s t, Monoid w) => MonadCompose (WriterT w m) (WriterT w n) s t 
MonadCompose m n s t => MonadCompose (StateT i m) (StateT i n) s t 
MonadCompose m n s t => MonadCompose (StateT i m) (StateT i n) s t 
Monad m => MonadCompose (ReaderT s m) (ReaderT t m) s t 
(MonadCompose m n s t, Error e) => MonadCompose (ErrorT e m) (ErrorT e n) s t 
(Monad m, Monoid w) => MonadCompose (RWST s w i m) (RWST t w i m) s t 
(Monad m, Monoid w) => MonadCompose (RWST s w i m) (RWST t w i m) s t 

(<<<) :: MonadCompose m n s t => m a -> n s -> n aSource

Compose two monadic values from right to left. Compare with Control.Category.<<<. f <<< g is equivalent to mcompose f g.

(>>>) :: MonadCompose m n s t => n s -> m a -> n aSource

Compose two monadic values from left to right. Compare with Control.Category.>>>. g >>> f is equivalent to mcompose f g.