|
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 return as the unit of the Identity monad and mzero 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 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
|
|
class Return m where |
The traditional return, note this probably has lost its type inference where you want to use it.
| | Methods | | | Instances | |
|
|
class Fail m where |
Restrict the cases where we allow pattern matching to fail. You have to explicitly supply this for your Monad
| | Methods | | | Instances | |
|
|
class (Functor m, Functor m', Functor m'') => Bind m m' m'' | m m' -> m'' where |
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 | | (>>) :: m a -> m' b -> m'' b |
| | Instances | |
|
|
(=<<) :: Bind m m' m'' => (a -> m' b) -> m a -> m'' b |
|
Rebound MonadPlus
|
|
class MPlus m m' m'' | m m' -> m'' where |
Break out mplus
| | Methods | mplus :: m a -> m' a -> m'' a |
| | Instances | |
|
|
class MonadZero m where |
Traditional mzero, note this probably has lost its type inference.
You probably want mzero.
| | Methods | | | Instances | |
|
|
A bottom monad
|
|
data MZero a |
Same trick using with Identity to build a canonical return, here we exploit the MonadPlus laws to make a canonical mzero. Has no members except bottom.
| Instances | |
|
|
Convenient class aliases
|
|
class (Fail m, Return m, Bind m m m) => Monad m |
When a parameterized monad can be used without varying its parameter, we can get the ease of use of the original Monad class.
| | Instances | |
|
|
class (MPlus m m m, MonadZero m) => MonadPlus m |
Class alias to get back an approximation of the original, easy-to-specify MonadPlus class where available
| | Instances | |
|
|
Traditional interfaces
|
|
class Go n m where |
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 | go :: n a -> m a | Usage: go (do something)
|
| | Instances | |
|
|
return :: a -> Identity a |
An inferable version of return
|
|
mzero :: MZero a |
An inferable version of mzero
|
|
Export common monads in this sugar
|
|
module Control.Concurrent.STM |
|
module Control.Monad.Cont |
|
module Control.Monad.Cont.Class |
|
module Control.Monad.Error |
|
module Control.Monad.Error.Class |
|
module Control.Monad.Fix |
|
module Control.Monad.Identity |
|
module Control.Monad.List |
|
module Control.Monad.Reader |
|
module Control.Monad.State |
|
module Control.Monad.Writer.Class |
|
mapM |
|
mapM_ |
|
forM |
|
forM_ |
|
sequence |
|
sequence_ |
|
join |
|
msum |
|
filterM |
|
mapAndUnzipM |
|
zipWithM |
|
zipWithM_ |
|
foldM |
|
foldM_ |
|
replicateM |
|
replicateM_ |
|
guard |
|
when |
|
unless |
|
liftM |
|
liftM2 |
|
liftM3 |
|
liftM4 |
|
liftM5 |
|
ap |
|
Produced by Haddock version 0.8 |