| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Control.Monad.Compat
Synopsis
- module Control.Monad
- module Control.Monad.Fail
- class Applicative m => Monad (m :: Type -> Type)
- class Monad m => MonadFail (m :: Type -> Type)
- fail :: MonadFail m => String -> m a
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
Documentation
module Control.Monad
module Control.Monad.Fail
class Applicative m => Monad (m :: Type -> Type) #
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:
- Left identity
returna>>=k = k a- Right identity
m>>=return= m- Associativity
m>>=(\x -> k x>>=h) = (m>>=k)>>=h
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.
Minimal complete definition
Instances
| Monad Complex | Since: base-4.9.0.0 |
| Monad Identity | Since: base-4.8.0.0 |
| Monad First | Since: base-4.8.0.0 |
| Monad Last | Since: base-4.8.0.0 |
| Monad Down | Since: base-4.11.0.0 |
| Monad First | Since: base-4.9.0.0 |
| Monad Last | Since: base-4.9.0.0 |
| Monad Max | Since: base-4.9.0.0 |
| Monad Min | Since: base-4.9.0.0 |
| Monad Dual | Since: base-4.8.0.0 |
| Monad Product | Since: base-4.8.0.0 |
| Monad Sum | Since: base-4.8.0.0 |
| Monad NonEmpty | Since: base-4.9.0.0 |
| Monad STM | Since: base-4.3.0.0 |
| Monad NoIO | Since: base-4.4.0.0 |
| Monad Par1 | Since: base-4.9.0.0 |
| Monad P | Since: base-2.1 |
| Monad ReadP | Since: base-2.1 |
| Monad ReadPrec | Since: base-2.1 |
| Monad IO | Since: base-2.1 |
| Monad Maybe | Since: base-2.1 |
| Monad Solo | Since: base-4.15 |
| Monad [] | Since: base-2.1 |
| Monad m => Monad (WrappedMonad m) | Since: base-4.7.0.0 |
Defined in Control.Applicative Methods (>>=) :: WrappedMonad m a -> (a -> WrappedMonad m b) -> WrappedMonad m b # (>>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # return :: a -> WrappedMonad m a # | |
| ArrowApply a => Monad (ArrowMonad a) | Since: base-2.1 |
Defined in Control.Arrow Methods (>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b # (>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b # return :: a0 -> ArrowMonad a a0 # | |
| Monad (ST s) | Since: base-2.1 |
| Monad (Either e) | Since: base-4.4.0.0 |
| Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Monad (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| Monad (ST s) | Since: base-2.1 |
| Monoid a => Monad ((,) a) | Since: base-4.9.0.0 |
| Monad m => Monad (Kleisli m a) | Since: base-4.14.0.0 |
| Monad f => Monad (Ap f) | Since: base-4.12.0.0 |
| Monad f => Monad (Alt f) | Since: base-4.8.0.0 |
| Monad f => Monad (Rec1 f) | Since: base-4.9.0.0 |
| (Monoid a, Monoid b) => Monad ((,,) a b) | Since: base-4.14.0.0 |
| (Monad f, Monad g) => Monad (Product f g) | Since: base-4.9.0.0 |
| (Monad f, Monad g) => Monad (f :*: g) | Since: base-4.9.0.0 |
| (Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) | Since: base-4.14.0.0 |
| Monad ((->) r) | Since: base-2.1 |
| Monad f => Monad (M1 i c f) | Since: base-4.9.0.0 |
class Monad m => MonadFail (m :: Type -> Type) #
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
fail s should be an action that runs in the monad itself, not an
exception (except in instances of MonadIO). In particular,
fail should not be implemented in terms of error.
Since: base-4.9.0.0
Minimal complete definition
Instances
| MonadFail P | Since: base-4.9.0.0 |
Defined in Text.ParserCombinators.ReadP | |
| MonadFail ReadP | Since: base-4.9.0.0 |
Defined in Text.ParserCombinators.ReadP | |
| MonadFail ReadPrec | Since: base-4.9.0.0 |
Defined in Text.ParserCombinators.ReadPrec | |
| MonadFail IO | Since: base-4.9.0.0 |
Defined in Control.Monad.Fail | |
| MonadFail Maybe | Since: base-4.9.0.0 |
Defined in Control.Monad.Fail | |
| MonadFail [] | Since: base-4.9.0.0 |
Defined in Control.Monad.Fail | |
| MonadFail f => MonadFail (Ap f) | Since: base-4.12.0.0 |
Defined in Data.Monoid | |
class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #
Monads that also support choice and failure.
Minimal complete definition
Nothing
Methods
The identity of mplus. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
The default definition is
mzero = empty
An associative operation. The default definition is
mplus = (<|>)
Instances
| MonadPlus STM | Takes the first non- Since: base-4.3.0.0 |
| MonadPlus P | Since: base-2.1 |
Defined in Text.ParserCombinators.ReadP | |
| MonadPlus ReadP | Since: base-2.1 |
| MonadPlus ReadPrec | Since: base-2.1 |
| MonadPlus IO | Takes the first non-throwing Since: base-4.9.0.0 |
| MonadPlus Maybe | Picks the leftmost Since: base-2.1 |
| MonadPlus [] | Combines lists by concatenation, starting from the empty list. Since: base-2.1 |
| (ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow | |
| MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
| MonadPlus (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| MonadPlus m => MonadPlus (Kleisli m a) | Since: base-4.14.0.0 |
| MonadPlus f => MonadPlus (Ap f) | Since: base-4.12.0.0 |
| MonadPlus f => MonadPlus (Alt f) | Since: base-4.8.0.0 |
| MonadPlus f => MonadPlus (Rec1 f) | Since: base-4.9.0.0 |
| (MonadPlus f, MonadPlus g) => MonadPlus (Product f g) | Since: base-4.9.0.0 |
| (MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) | Since: base-4.9.0.0 |
| MonadPlus f => MonadPlus (M1 i c f) | Since: base-4.9.0.0 |