|
| Control.Monad.Parameterized | | Portability | non-portable (requires the kitchen sink) | | Stability | experimental | | Maintainer | Edward Kmett <ekmett@gmail.com> |
|
|
|
|
|
| Description |
Implements a notion of parameterized monad by varying the monad itself, this lets us
avoid having to carry a parameter around for monads that do not need it, and we can rederive
the normal notion of a parameterized monad from this variation for those that do.
The signature of >>= costs us type inference for the types of return and mzero,
so we restore that by defining returnM as the unit of the Identity monad and mzeroM as
the unit of the trivial bottom monad, and appealing to the monad laws to allow these to combine
with all other monads satisfying the monad laws through >>=
Caveat: this currently does not permit types to vary under the do-sugar because of assumptions in GHC
about the shape of >>=.
This imports and defines the correct instances for a good portion of the MTL, primarily because
it is so awkward to import them all otherwise due to the fact that most of them re-export the Control.Monad.Monad syntax.
Does not export Control.Monad.ST or Control.Monad.Writer since it is unclear if you want strict or lazy versions in scope
|
|
| Synopsis |
|
|
|
|
| Rebound Monad
|
|
|
| Traditional return, note this probably has lost its type inference where you want to use it.
You probably want to use returnM
| | | Methods | | | Instances | |
|
|
|
| Restrict the cases where we allow pattern matching to fail. You have to explicitly supply this for your Monad
| | | Methods | | | Instances | |
|
|
|
| Implement parameterized monads like Oleg's restricted monads, but vary the monad itself rather than restrict its parameters
| | | Methods | | (>>=) :: m a -> (a -> m' b) -> m'' b | Source |
| | | (>>) :: m a -> m' b -> m'' b | Source |
|
| | Instances | |
|
|
| (=<<) :: Bind m m' m'' => (a -> m' b) -> m a -> m'' b | Source |
|
|
| Rebound MonadPlus
|
|
| class MPlus m m' m'' | m m' -> m'' where | Source |
|
| Break out mplus
| | | Methods | | mplus :: m a -> m' a -> m'' a | Source |
|
| | Instances | |
|
|
|
| Traditional mzero, note this probably has lost its type inference.
You probably want mzeroM.
| | | Methods | | | Instances | |
|
|
| Convenient class aliases
|
|
|
| When a parameterized monad can be used without varying its parameter, we can get the ease of use of the original Monad class.
|
|
|
|
| Class alias to get back an approximation of the original, easy-to-specify MonadPlus class where available
|
|
|
| Restoring type inference
|
|
|
| Now of course we can have MZeros and Identitys float to the top of a do expression, so we need a way to convert them to any Monad or MonadPlus instance respectively
| | | Methods | | | Instances | |
|
|
|
| An inferable version of return
|
|
|
| An inferable version of mzero
|
|
|
| Same trick using with Identity to build a canonical returnM, here we exploit the MonadPlus laws to make a canonical mzeroM. Has no members except bottom.
| Instances | |
|
|
| Export common monads in this sugar
|
|
| Produced by Haddock version 2.3.0 |