| Copyright | (c) The University of Glasgow 2001 |
|---|---|
| License | BSD-style (see the file libraries/base/LICENSE) |
| Maintainer | libraries@haskell.org |
| Stability | provisional |
| Portability | portable |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Control.Monad.Instances
Description
TheFunctor class is used for types that can be mapped over.Instances ofFunctor should satisfy the following laws:
fmap id == idfmap (f . g) == fmap f . fmap g
The instances ofFunctor for lists,Maybe andIOsatisfy these laws.
Minimal complete definition
classApplicative m =>Monad mwhereSource#
TheMonad class defines the basic operations over amonad,a concept from a branch of mathematics known ascategory theory.From the perspective of a Haskell programmer, however, it is best tothink of a monad as anabstract datatype of actions.Haskell'sdo expressions provide a convenient syntax for writingmonadic expressions.
Instances ofMonad should satisfy the following laws:
Furthermore, theMonad andApplicative operations should relate as follows:
The above laws imply:
and thatpure and (<*>) satisfy the applicative functor laws.
The instances ofMonad for lists,Maybe andIOdefined in thePrelude satisfy these laws.
Minimal complete definition
Methods
(>>=) ::forall a b. m a -> (a -> m b) -> m binfixl 1Source#
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
(>>) ::forall a b. m a -> m b -> m binfixl 1Source#
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 ado expression.
As part of the MonadFail proposal (MFP), this function is moved to its own classMonadFail (seeControl.Monad.Fail for more details). The definition here will be removed in a future release.
Produced byHaddock version 2.20.0