monad-param-0.0.1: Parameterized monadsSource codeContentsIndex
Control.Monad.Parameterized
Portabilitynon-portable (requires the kitchen sink)
Stabilityexperimental
MaintainerEdward Kmett <ekmett@gmail.com>
Contents
Rebound Monad
Rebound MonadPlus
Convenient class aliases
Restoring type inference
Export common monads in this sugar
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
class Return m where
return :: a -> m a
class Fail m where
fail :: String -> m a
class (Functor m, Functor m', Functor m'') => Bind m m' m'' | m m' -> m'' where
(>>=) :: m a -> (a -> m' b) -> m'' b
(>>) :: m a -> m' b -> m'' b
(=<<) :: Bind m m' m'' => (a -> m' b) -> m a -> m'' b
class MPlus m m' m'' | m m' -> m'' where
mplus :: m a -> m' a -> m'' a
class MonadZero m where
mzero :: m a
class (Fail m, Return m, Bind m m m) => Monad m
class (MPlus m m m, MonadZero m) => MonadPlus m
class Go n m where
go :: n a -> m a
returnM :: a -> Identity a
mzeroM :: MZero a
data MZero a
Rebound Monad
class Return m whereSource
Traditional return, note this probably has lost its type inference where you want to use it. You probably want to use returnM
Methods
return :: a -> m aSource
show/hide Instances
class Fail m whereSource
Restrict the cases where we allow pattern matching to fail. You have to explicitly supply this for your Monad
Methods
fail :: String -> m aSource
show/hide Instances
Fail []
Fail IO
Fail STM
Fail Maybe
Fail (ST s)
Fail (ST s)
Fail (Cont r)
Monoid w => Fail (Writer w)
Monoid w => Fail (Writer w)
Fail (State s)
Fail (Reader e)
Monad m => Fail (ListT m)
Monad m => Fail (ContT r m)
(Monad m, Monoid w) => Fail (WriterT w m)
(Monad m, Monoid w) => Fail (WriterT w m)
Monad m => Fail (StateT s m)
Monad m => Fail (ReaderT e m)
(Monad m, Error e) => Fail (ErrorT e m)
class (Functor m, Functor m', Functor m'') => Bind m m' m'' | m m' -> m'' whereSource
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'' bSource
(>>) :: m a -> m' b -> m'' bSource
show/hide Instances
(=<<) :: Bind m m' m'' => (a -> m' b) -> m a -> m'' bSource
Rebound MonadPlus
class MPlus m m' m'' | m m' -> m'' whereSource
Break out mplus
Methods
mplus :: m a -> m' a -> m'' aSource
show/hide Instances
class MonadZero m whereSource
Traditional mzero, note this probably has lost its type inference. You probably want mzeroM.
Methods
mzero :: m aSource
show/hide Instances
Convenient class aliases
class (Fail m, Return m, Bind m m m) => Monad m Source
When a parameterized monad can be used without varying its parameter, we can get the ease of use of the original Monad class.
class (MPlus m m m, MonadZero m) => MonadPlus m Source
Class alias to get back an approximation of the original, easy-to-specify MonadPlus class where available
Restoring type inference
class Go n m whereSource
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 aSource
Usage: go (do something)
show/hide Instances
returnM :: a -> Identity aSource
An inferable version of return
mzeroM :: MZero aSource
An inferable version of mzero
data MZero a Source
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.
show/hide Instances
Export common monads in this sugar
Produced by Haddock version 2.3.0