-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Parameterized monads -- -- Implements parameterized monads by overloading the monad sugar with -- more liberal types. @package monad-param @version 0.0.2 -- | 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 -- 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 module Control.Monad.Parameterized -- | The traditional return, note this probably has lost its type -- inference where you want to use it. class Return m returnM :: (Return m) => a -> m a -- | Restrict the cases where we allow pattern matching to fail. You -- have to explicitly supply this for your Monad class Fail m fail :: (Fail m) => String -> m a -- | Implement parameterized monads like Oleg's restricted monads, but vary -- the monad itself rather than restrict its parameters class (Functor m, Functor m', Functor m'') => Bind m m' m'' | m m' -> m'' (>>=) :: (Bind m m' m'') => m a -> (a -> m' b) -> (m'' b) (>>) :: (Bind m m' m'') => m a -> m' b -> m'' b (=<<) :: (Bind m m' m'') => (a -> m' b) -> m a -> m'' b -- | Break out mplus class MPlus m m' m'' | m m' -> m'' mplus :: (MPlus m m' m'') => m a -> m' a -> m'' a -- | Traditional Control.Monad.mzero, note this probably has lost -- its type inference. You probably want mzero. class MonadZero m mzeroM :: (MonadZero m) => m 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. data MZero a -- | When a parameterized monad can be used without varying its parameter, -- we can get the ease of use of the original Monad class. class (Fail m, Return m, Bind m m m) => Monad m -- | Class alias to get back an approximation of the original, -- easy-to-specify MonadPlus class where available class (MPlus m m m, MonadZero m) => MonadPlus m -- | 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 class Go n m go :: (Go n m) => n a -> m a -- | An inferable version of Prelude.return return :: a -> Identity a -- | An inferable version of Control.Monad.mzero mzero :: MZero a -- | mapM f is equivalent to sequence . -- map f. mapM :: (Monad m) => (a -> m b) -> [a] -> m [b] -- | mapM_ f is equivalent to sequence_ . -- map f. mapM_ :: (Monad m) => (a -> m b) -> [a] -> m () -- | forM is mapM with its arguments flipped forM :: (Monad m) => [a] -> (a -> m b) -> m [b] -- | forM_ is mapM_ with its arguments flipped forM_ :: (Monad m) => [a] -> (a -> m b) -> m () -- | Evaluate each action in the sequence from left to right, and collect -- the results. sequence :: (Monad m) => [m a] -> m [a] -- | Evaluate each action in the sequence from left to right, and ignore -- the results. sequence_ :: (Monad m) => [m a] -> m () -- | The join function is the conventional monad join operator. It -- is used to remove one level of monadic structure, projecting its bound -- argument into the outer level. join :: (Monad m) => m (m a) -> m a -- | This generalizes the list-based concat function. msum :: (MonadPlus m) => [m a] -> m a -- | This generalizes the list-based filter function. filterM :: (Monad m) => (a -> m Bool) -> [a] -> m [a] -- | The mapAndUnzipM function maps its first argument over a list, -- returning the result as a pair of lists. This function is mainly used -- with complicated data structures or a state-transforming monad. mapAndUnzipM :: (Monad m) => (a -> m (b, c)) -> [a] -> m ([b], [c]) -- | The zipWithM function generalizes zipWith to arbitrary -- monads. zipWithM :: (Monad m) => (a -> b -> m c) -> [a] -> [b] -> m [c] -- | zipWithM_ is the extension of zipWithM which ignores the -- final result. zipWithM_ :: (Monad m) => (a -> b -> m c) -> [a] -> [b] -> m () -- | The foldM function is analogous to foldl, except that -- its result is encapsulated in a monad. Note that foldM works -- from left-to-right over the list arguments. This could be an issue -- where '(>>)' and the `folded function' are not commutative. -- -- foldM f a1 [x1, x2, ..., xm ] -- -- == -- -- do a2 <- f a1 x1 a3 <- f a2 x2 ... f am xm -- -- If right-to-left evaluation is required, the input list should be -- reversed. foldM :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m a -- | Like foldM, but discards the result. foldM_ :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m () -- | replicateM n act performs the action n times, -- gathering the results. replicateM :: (Monad m) => Int -> m a -> m [a] -- | Like replicateM, but discards the result. replicateM_ :: (Monad m) => Int -> m a -> m () -- | guard b is return () if b is -- True, and mzero if b is False. guard :: (MonadPlus m) => Bool -> m () -- | Conditional execution of monadic expressions. For example, -- -- when debug (putStr "Debugging\n") -- -- will output the string Debugging\n if the Boolean value -- debug is True, and otherwise do nothing. when :: (Monad m) => Bool -> m () -> m () -- | The reverse of when. unless :: (Monad m) => Bool -> m () -> m () -- | Promote a function to a monad. liftM :: (Monad m) => (a1 -> r) -> m a1 -> m r -- | Promote a function to a monad, scanning the monadic arguments from -- left to right. For example, -- -- liftM2 (+) [0,1] [0,2] = [0,2,1,3] liftM2 (+) (Just 1) Nothing = -- Nothing liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r -- | Promote a function to a monad, scanning the monadic arguments from -- left to right (cf. liftM2). liftM3 :: (Monad m) => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r -- | Promote a function to a monad, scanning the monadic arguments from -- left to right (cf. liftM2). liftM4 :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r -- | Promote a function to a monad, scanning the monadic arguments from -- left to right (cf. liftM2). liftM5 :: (Monad m) => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r -- | In many situations, the liftM operations can be replaced by -- uses of ap, which promotes function application. -- -- return f `ap` x1 `ap` ... `ap` xn -- -- is equivalent to -- -- liftMn f x1 x2 ... xn ap :: (Monad m) => m (a -> b) -> m a -> m b instance [overlap ok] Bind [] IO (ListT IO) instance [overlap ok] Bind IO STM IO instance [overlap ok] Bind STM IO IO instance [overlap ok] Bind [] Maybe [] instance [overlap ok] Bind Maybe [] [] instance [overlap ok] (Monad m) => Bind (ContT r m) (ContT r m) (ContT r m) instance [overlap ok] (Monad m) => Fail (ContT r m) instance [overlap ok] (Monad m) => Return (ContT r m) instance [overlap ok] (Monad m, Error e) => MPlus (ErrorT e m) (ErrorT e m) (ErrorT e m) instance [overlap ok] (Monad m, Error e) => MonadZero (ErrorT e m) instance [overlap ok] (Monad m, Error e) => Bind (ErrorT e m) (ErrorT e m) (ErrorT e m) instance [overlap ok] (Monad m, Error e) => Fail (ErrorT e m) instance [overlap ok] (Monad m, Error e) => Return (ErrorT e m) instance [overlap ok] (Monad m, Monoid w) => Bind (WriterT w m) (WriterT w m) (WriterT w m) instance [overlap ok] (Monad m, Monoid w) => Fail (WriterT w m) instance [overlap ok] (Monad m, Monoid w) => Return (WriterT w m) instance [overlap ok] (Monad m, Monoid w) => Bind (WriterT w m) (WriterT w m) (WriterT w m) instance [overlap ok] (Monad m, Monoid w) => Fail (WriterT w m) instance [overlap ok] (Monad m, Monoid w) => Return (WriterT w m) instance [overlap ok] (Monad m) => Bind (ReaderT e m) (ReaderT e m) (ReaderT e m) instance [overlap ok] (Monad m) => Fail (ReaderT e m) instance [overlap ok] (Monad m) => Return (ReaderT e m) instance [overlap ok] (Monad m) => Bind (StateT s m) (StateT s m) (StateT s m) instance [overlap ok] (Monad m) => Fail (StateT s m) instance [overlap ok] (Monad m) => Return (StateT s m) instance [overlap ok] (Monad m) => MPlus (ListT m) (ListT m) (ListT m) instance [overlap ok] (Monad m) => MonadZero (ListT m) instance [overlap ok] (Monad m) => Bind (ListT m) (ListT m) (ListT m) instance [overlap ok] (Monad m) => Fail (ListT m) instance [overlap ok] (Monad m) => Return (ListT m) instance [overlap ok] (Monoid w) => Bind (Writer w) (Writer w) (Writer w) instance [overlap ok] (Monoid w) => Fail (Writer w) instance [overlap ok] (Monoid w) => Return (Writer w) instance [overlap ok] (Monoid w) => Bind (Writer w) (Writer w) (Writer w) instance [overlap ok] (Monoid w) => Fail (Writer w) instance [overlap ok] (Monoid w) => Return (Writer w) instance [overlap ok] Bind (ST s) (ST s) (ST s) instance [overlap ok] Fail (ST s) instance [overlap ok] Return (ST s) instance [overlap ok] Bind (ST s) (ST s) (ST s) instance [overlap ok] Fail (ST s) instance [overlap ok] Return (ST s) instance [overlap ok] Bind (Cont r) (Cont r) (Cont r) instance [overlap ok] Fail (Cont r) instance [overlap ok] Return (Cont r) instance [overlap ok] Bind (Reader e) (Reader e) (Reader e) instance [overlap ok] Fail (Reader e) instance [overlap ok] Return (Reader e) instance [overlap ok] Bind (State s) (State s) (State s) instance [overlap ok] Fail (State s) instance [overlap ok] Return (State s) instance [overlap ok] Bind IO IO IO instance [overlap ok] Fail IO instance [overlap ok] Return IO instance [overlap ok] Bind STM STM STM instance [overlap ok] Fail STM instance [overlap ok] Return STM instance [overlap ok] MPlus [] [] [] instance [overlap ok] MonadZero [] instance [overlap ok] Bind [] [] [] instance [overlap ok] Fail [] instance [overlap ok] Return [] instance [overlap ok] MPlus Maybe Maybe Maybe instance [overlap ok] MonadZero Maybe instance [overlap ok] Bind Maybe Maybe Maybe instance [overlap ok] Fail Maybe instance [overlap ok] Return Maybe instance [overlap ok] (MPlus m m m, MonadZero m) => MonadPlus m instance [overlap ok] Return MZero instance [overlap ok] Return Identity instance [overlap ok] Go a a instance [overlap ok] (MonadZero a) => Go MZero a instance [overlap ok] (Return a) => Go Identity a instance [overlap ok] Bind MZero Identity MZero instance [overlap ok] Bind Identity MZero MZero instance [overlap ok] Bind MZero MZero MZero instance [overlap ok] (Functor a) => Bind a MZero MZero instance [overlap ok] (Functor a) => Bind MZero a MZero instance [overlap ok] MPlus MZero MZero MZero instance [overlap ok] MPlus a MZero a instance [overlap ok] MPlus MZero a a instance [overlap ok] Functor MZero instance [overlap ok] (Fail m, Return m, Bind m m m) => Monad m instance [overlap ok] Bind Identity Identity Identity instance [overlap ok] (Functor a) => Bind a Identity a instance [overlap ok] (Functor a) => Bind Identity a a