Portability | portable |
---|---|
Stability | experimental |
This module provides Arrow-like monad composition for monadLib. To be more precise, it is Category-like,
i.e. the parallels are to Control.Category.Category
.
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.
The motivation to create this module was a nagging feeling when reading the documentation for hxt
and HaXml
:
composing filters is very nice, but the abundance of constant arrows, and the lack of access to the very extensive
set of monad combinators, leads to duplicated effort and unwieldy code (in my humble opinion). I think it is
possible to gain similar functionality with a stack of monad transformers including ReaderT
, and ComposeM
,
presented here.
- mid :: ReaderM m s => m s
- class (Monad m, Monad n) => ComposeM m n s t | m -> s, n -> t, n s -> m where
- (<<<) :: ComposeM m n s t => m a -> n s -> n a
- (>>>) :: ComposeM m n s t => n s -> m a -> n a
- derive_mcompose :: ComposeM m n s t => Iso m o -> Iso n p -> o a -> p s -> p a
- derive_mapply :: ComposeM m n s t => Iso m o -> Iso n p -> o a -> s -> p a
Documentation
class (Monad m, Monad n) => ComposeM 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.
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.
ComposeM ((->) s) ((->) t) s t | |
ComposeM (Reader s) (Reader t) s t | |
ComposeM m n s t => ComposeM (IdT m) (IdT n) s t | |
ComposeM m n s t => ComposeM (ChoiceT m) (ChoiceT n) s t | |
Monad m => ComposeM (ReaderT s m) (ReaderT t m) s t | |
(ComposeM m n s t, Monoid w) => ComposeM (WriterT w m) (WriterT w n) s t | |
ComposeM m n s t => ComposeM (StateT i m) (StateT i n) s t | |
ComposeM m n s t => ComposeM (ExceptionT e m) (ExceptionT e n) s t |
(<<<) :: ComposeM 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
.
(>>>) :: ComposeM 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
.
derive_mcompose :: ComposeM m n s t => Iso m o -> Iso n p -> o a -> p s -> p aSource
derive_mapply :: ComposeM m n s t => Iso m o -> Iso n p -> o a -> s -> p aSource