Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
This module reexports functions to work with monads.
- module Control.Monad.Except
- module Control.Monad.Reader
- module Control.Monad.State.Strict
- module Control.Monad.Trans
- module Control.Monad.Trans.Identity
- module Control.Monad.Trans.Maybe
- module Data.Maybe
- module Data.Either
- class Applicative m => Monad (m :: * -> *) where
- class Monad m => MonadFail (m :: * -> *) where
- class (Alternative m, Monad m) => MonadPlus (m :: * -> *) where
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- forever :: Applicative f => f a -> f b
- join :: Monad m => m (m a) -> m a
- mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a
- filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a]
- mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c])
- zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c]
- zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m ()
- foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
- foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m ()
- replicateM :: Applicative m => Int -> m a -> m [a]
- replicateM_ :: Applicative m => Int -> m a -> m ()
- 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
- ap :: Monad m => m (a -> b) -> m a -> m b
- (<$!>) :: Monad m => (a -> b) -> m a -> m b
Reexport transformers
module Control.Monad.Except
module Control.Monad.Reader
module Control.Monad.State.Strict
module Control.Monad.Trans
module Control.Monad.Trans.Identity
module Control.Monad.Trans.Maybe
Reexport Maybe
module Data.Maybe
Reexport Either
module Data.Either
class Applicative m => Monad (m :: * -> *) where #
The 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.
Haskell's do
expressions provide a convenient syntax for writing
monadic expressions.
Instances of Monad
should satisfy the following laws:
Furthermore, the Monad
and Applicative
operations should relate as follows:
The above laws imply:
and that pure
and (<*>
) satisfy the applicative functor laws.
The instances of Monad
for lists, Maybe
and IO
defined in the Prelude satisfy these laws.
(>>=) :: m a -> (a -> m b) -> m b infixl 1 #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
(>>) :: m a -> m b -> m b infixl 1 #
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.
Monad [] | Since: 2.1 |
Monad Maybe | Since: 2.1 |
Monad IO | Since: 2.1 |
Monad Par1 | Since: 4.9.0.0 |
Monad Q | |
Monad P | Since: 2.1 |
Monad Complex | Since: 4.9.0.0 |
Monad Min | Since: 4.9.0.0 |
Monad Max | Since: 4.9.0.0 |
Monad First | Since: 4.9.0.0 |
Monad Last | Since: 4.9.0.0 |
Monad Option | Since: 4.9.0.0 |
Monad NonEmpty | Since: 4.9.0.0 |
Monad Identity | Since: 4.8.0.0 |
Monad STM | Since: 4.3.0.0 |
Monad Dual | Since: 4.8.0.0 |
Monad Sum | Since: 4.8.0.0 |
Monad Product | Since: 4.8.0.0 |
Monad First | |
Monad Last | |
Monad ReadPrec | Since: 2.1 |
Monad ReadP | Since: 2.1 |
Monad Put | |
Monad Tree | |
Monad Seq | |
Monad Array | |
Monad Vector | |
Monad (Either e) | Since: 4.4.0.0 |
Monad (U1 *) | Since: 4.9.0.0 |
Monoid a => Monad ((,) a) | Since: 4.9.0.0 |
Monad (ST s) | Since: 2.1 |
Monad m => Monad (WrappedMonad m) | |
ArrowApply a => Monad (ArrowMonad a) | Since: 2.1 |
Monad (Proxy *) | Since: 4.7.0.0 |
Monad (State s) | |
Monad m => Monad (MaybeT m) | |
Monad m => Monad (ListT m) | |
Monad f => Monad (Rec1 * f) | Since: 4.9.0.0 |
Monad f => Monad (Alt * f) | |
(Applicative f, Monad f) => Monad (WhenMissing f x) | Equivalent to |
Monad m => Monad (ExceptT e m) | |
Monad m => Monad (StateT s m) | |
Monad m => Monad (StateT s m) | |
(Monad m, Error e) => Monad (ErrorT e m) | |
Monad m => Monad (StateT s m) | |
(Monoid w, Monad m) => Monad (WriterT w m) | |
(Monoid w, Monad m) => Monad (WriterT w m) | |
Monad m => Monad (IdentityT * m) | |
Monad ((->) LiftedRep LiftedRep r) | Since: 2.1 |
(Monad f, Monad g) => Monad ((:*:) * f g) | Since: 4.9.0.0 |
(Monad f, Monad g) => Monad (Product * f g) | Since: 4.9.0.0 |
(Monad f, Applicative f) => Monad (WhenMatched f x y) | Equivalent to |
(Applicative f, Monad f) => Monad (WhenMissing f k x) | Equivalent to |
Monad m => Monad (ReaderT * r m) | |
Monad f => Monad (M1 * i c f) | Since: 4.9.0.0 |
(Monad f, Applicative f) => Monad (WhenMatched f k x y) | Equivalent to |
(Monoid w, Monad m) => Monad (RWST r w s m) | |
(Monoid w, Monad m) => Monad (RWST r w s m) | |
class Monad m => MonadFail (m :: * -> *) where #
When a value is bound in do
-notation, the pattern on the left
hand side of <-
might not match. In this case, this class
provides a function to recover.
A Monad
without a MonadFail
instance may only be used in conjunction
with pattern that always match, such as newtypes, tuples, data types with
only a single data constructor, and irrefutable patterns (~pat
).
Instances of MonadFail
should satisfy the following law: fail s
should
be a left zero for >>=
,
fail s >>= f = fail s
If your Monad
is also MonadPlus
, a popular definition is
fail _ = mzero
Since: 4.9.0.0
MonadFail [] | Since: 4.9.0.0 |
MonadFail Maybe | Since: 4.9.0.0 |
MonadFail IO | Since: 4.9.0.0 |
MonadFail Q | |
MonadFail P | Since: 4.9.0.0 |
MonadFail ReadPrec | Since: 4.9.0.0 |
MonadFail ReadP | Since: 4.9.0.0 |
Monad m => MonadFail (MaybeT m) | |
Monad m => MonadFail (ListT m) | |
MonadFail m => MonadFail (ExceptT e m) | |
MonadFail m => MonadFail (StateT s m) | |
MonadFail m => MonadFail (StateT s m) | |
(Monad m, Error e) => MonadFail (ErrorT e m) | |
MonadFail m => MonadFail (StateT s m) | |
(Monoid w, MonadFail m) => MonadFail (WriterT w m) | |
(Monoid w, MonadFail m) => MonadFail (WriterT w m) | |
MonadFail m => MonadFail (IdentityT * m) | |
MonadFail m => MonadFail (ReaderT * r m) | |
(Monoid w, MonadFail m) => MonadFail (RWST r w s m) | |
(Monoid w, MonadFail m) => MonadFail (RWST r w s m) | |
class (Alternative m, Monad m) => MonadPlus (m :: * -> *) where #
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
(=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 #
Same as >>=
, but with the arguments interchanged.
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 #
Left-to-right Kleisli composition of monads.
forever :: Applicative f => f a -> f b #
repeats the action infinitely.forever
act
join :: Monad m => m (m a) -> m a #
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.
filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a] #
This generalizes the list-based filter
function.
mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c]) #
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.
zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c] #
zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m () #
foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b #
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_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m () #
Like foldM
, but discards the result.
replicateM :: Applicative m => Int -> m a -> m [a] #
performs the action replicateM
n actn
times,
gathering the results.
replicateM_ :: Applicative m => Int -> m a -> m () #
Like replicateM
, but discards the result.
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. For example,
liftM2 (+) [0,1] [0,2] = [0,2,1,3] liftM2 (+) (Just 1) Nothing = Nothing
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 #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).