monad-param-0.0.2: Parameterized monadsContentsIndex
Control.Monad.Parameterized
Portabilitynon-portable (requires the kitchen sink)
Stabilityexperimental
MaintainerEdward Kmett <ekmett@gmail.com>
Contents
Rebound Monad
Rebound MonadPlus
A bottom monad
Convenient class aliases
Traditional interfaces
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 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
class Return m where
returnM :: 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
mzeroM :: m a
data MZero 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
return :: a -> Identity a
mzero :: MZero a
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
Rebound Monad
class Return m where
The traditional return, note this probably has lost its type inference where you want to use it.
Methods
returnM :: a -> m a
show/hide 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
fail :: String -> m a
show/hide Instances
Fail IO
Fail Maybe
Fail STM
Fail []
Fail (Cont r)
Monad m => Fail (ListT m)
Fail (Reader e)
Fail (ST s)
Fail (ST s)
Fail (State s)
Monoid w => Fail (Writer w)
Monoid w => Fail (Writer w)
Monad m => Fail (ContT r m)
(Monad m, Error e) => Fail (ErrorT e m)
Monad m => Fail (ReaderT e m)
Monad m => Fail (StateT s m)
(Monad m, Monoid w) => Fail (WriterT w m)
(Monad m, Monoid w) => Fail (WriterT w m)
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
show/hide Instances
Bind IO IO IO
Bind IO STM IO
Bind Identity Identity Identity
Bind Identity MZero MZero
Functor a => Bind Identity a a
Bind MZero Identity MZero
Bind MZero MZero MZero
Functor a => Bind MZero a MZero
Bind Maybe Maybe Maybe
Bind Maybe [] []
Bind STM IO IO
Bind STM STM STM
Bind [] Maybe []
Bind [] [] []
Functor a => Bind a Identity a
Functor a => Bind a MZero MZero
Bind [] IO (ListT IO)
Bind (Cont r) (Cont r) (Cont r)
Monad m => Bind (ListT m) (ListT m) (ListT m)
Bind (Reader e) (Reader e) (Reader e)
Bind (ST s) (ST s) (ST s)
Bind (ST s) (ST s) (ST s)
Bind (State s) (State s) (State s)
Monoid w => Bind (Writer w) (Writer w) (Writer w)
Monoid w => Bind (Writer w) (Writer w) (Writer w)
Monad m => Bind (ContT r m) (ContT r m) (ContT r m)
(Monad m, Error e) => Bind (ErrorT e m) (ErrorT e m) (ErrorT e m)
Monad m => Bind (ReaderT e m) (ReaderT e m) (ReaderT e m)
Monad m => Bind (StateT s m) (StateT s m) (StateT s m)
(Monad m, Monoid w) => Bind (WriterT w m) (WriterT w m) (WriterT w m)
(Monad m, Monoid w) => Bind (WriterT w m) (WriterT w m) (WriterT w m)
(=<<) :: 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
show/hide Instances
class MonadZero m where
Traditional mzero, note this probably has lost its type inference. You probably want mzero.
Methods
mzeroM :: m a
show/hide 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.
show/hide 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.
show/hide Instances
(Fail m, Return m, Bind m m m) => Monad m
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
show/hide Instances
(MPlus m m m, MonadZero m) => MonadPlus m
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)
show/hide 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