- class Monad m => MonadPlus m where
- join :: Monad m => m (m a) -> m a
- guard :: MonadPlus m => Bool -> m ()
- when :: Monad m => Bool -> m () -> m ()
- unless :: Monad m => Bool -> m () -> m ()
- ap :: Monad m => m (a -> b) -> m a -> m b
- msum :: MonadPlus m => [m a] -> m a
- filterM :: Monad m => (a -> m Bool) -> [a] -> m [a]
- mapAndUnzipM :: Monad m => (a -> m (b, c)) -> [a] -> m ([b], [c])
- zipWithM :: Monad m => (a -> b -> m c) -> [a] -> [b] -> m [c]
- zipWithM_ :: Monad m => (a -> b -> m c) -> [a] -> [b] -> m ()
- foldM :: Monad m => (a -> b -> m a) -> a -> [b] -> m a
- liftM :: Monad m => (a1 -> r) -> m a1 -> m r
- liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
- liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
- liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
- liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
- class Monad m where
- class Functor f where
- fmap :: (a -> b) -> f a -> f b
- mapM :: Monad m => (a -> m b) -> [a] -> m [b]
- mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
- sequence :: Monad m => [m a] -> m [a]
- sequence_ :: Monad m => [m a] -> m ()
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
Monads that also support choice and failure.
the identity of
mplus. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
an associative operation
join function is the conventional monad join operator. It is used to
remove one level of monadic structure, projecting its bound argument into the
Conditional execution of monadic expressions. For example,
when debug (putStr "Debugging\n")
will output the string
Debugging\n if the Boolean value
and otherwise do nothing.
This generalizes the list-based
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.
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.
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
Monad class defines the basic operations over a monad,
a concept from a branch of mathematics known as category theory.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an abstract datatype of actions.
do expressions provide a convenient syntax for writing
Monad should satisfy the following laws:
return a >>= k == k a m >>= return == m m >>= (\x -> k x >>= h) == (m >>= k) >>= h
fmap f xs == xs >>= return . f
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
Inject a value into the monadic type.
Fail with a message. This operation is not part of the
mathematical definition of a monad, but is invoked on pattern-match
failure in a
fmap id == id fmap (f . g) == fmap f . fmap g
The instances of
Functor for lists,
satisfy these laws.
Evaluate each action in the sequence from left to right, and collect the results.
Evaluate each action in the sequence from left to right, and ignore the results.