base-compat-0.10.5: A compatibility layer for base

Safe Haskell | Safe
Language | Haskell98

Control.Monad.Compat

Synopsis

- module Control.Monad
- class Applicative m => Monad (m :: Type -> Type) where
  - (>>=) :: m a -> (a -> m b) -> m b
  - (>>) :: m a -> m b -> m b
  - return :: a -> m a
  - fail :: String -> m a
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
  - mzero :: m a
  - mplus :: m a -> m a -> m a

# Documentation

module Control.Monad

class Applicative m => Monad (m :: Type -> Type) where Source #

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:

-     return a >>= k  =  k a

-     m >>= return  =  m

-     m >>= (\x -> k x >>= h)  =  (m >>= k) >>= h

Furthermore, the `Monad` and `Applicative` operations should relate as follows:

-     pure = return

-     (<*>) = ap

The above laws imply:

-     fmap f xs  =  xs >>= return . f

-     (>>) = (*>)

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

(>>=)

Methods

(>>=) :: m a -> (a -> m b) -> m b infixl 1 Source #

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 Source #

Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.

return :: a -> m a Source #

Inject a value into the monadic type.

fail :: String -> m a Source #

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 `do` expression.

As part of the MonadFail proposal (MFP), this function is moved to its own class `MonadFail` (see Control.Monad.Fail for more details). The definition here will be removed in a future release.

Instances

Monad [] | Since: base-2.1
Instance details Defined in GHC.Base Methods (>>=) :: [a] -> (a -> [b]) -> [b] Source # (>>) :: [a] -> [b] -> [b] Source # return :: a -> [a] Source # fail :: String -> [a] Source #
Monad Maybe | Since: base-2.1
Instance details Defined in GHC.Base Methods (>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b Source # (>>) :: Maybe a -> Maybe b -> Maybe b Source # return :: a -> Maybe a Source # fail :: String -> Maybe a Source #
Monad IO | Since: base-2.1
Instance details Defined in GHC.Base Methods (>>=) :: IO a -> (a -> IO b) -> IO b Source # (>>) :: IO a -> IO b -> IO b Source # return :: a -> IO a Source # fail :: String -> IO a Source #
Monad Complex | Since: base-4.9.0.0
Instance details Defined in Data.Complex Methods (>>=) :: Complex a -> (a -> Complex b) -> Complex b Source # (>>) :: Complex a -> Complex b -> Complex b Source # return :: a -> Complex a Source # fail :: String -> Complex a Source #
Monad Min | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods (>>=) :: Min a -> (a -> Min b) -> Min b Source # (>>) :: Min a -> Min b -> Min b Source # return :: a -> Min a Source # fail :: String -> Min a Source #
Monad Max | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods (>>=) :: Max a -> (a -> Max b) -> Max b Source # (>>) :: Max a -> Max b -> Max b Source # return :: a -> Max a Source # fail :: String -> Max a Source #
Monad First | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods (>>=) :: First a -> (a -> First b) -> First b Source # (>>) :: First a -> First b -> First b Source # return :: a -> First a Source # fail :: String -> First a Source #
Monad Last | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods (>>=) :: Last a -> (a -> Last b) -> Last b Source # (>>) :: Last a -> Last b -> Last b Source # return :: a -> Last a Source # fail :: String -> Last a Source #
Monad Option | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods (>>=) :: Option a -> (a -> Option b) -> Option b Source # (>>) :: Option a -> Option b -> Option b Source # return :: a -> Option a Source # fail :: String -> Option a Source #
Monad Identity | Since: base-4.8.0.0
Instance details Defined in Data.Functor.Identity Methods (>>=) :: Identity a -> (a -> Identity b) -> Identity b Source # (>>) :: Identity a -> Identity b -> Identity b Source # return :: a -> Identity a Source # fail :: String -> Identity a Source #
Monad STM | Since: base-4.3.0.0
Instance details Defined in GHC.Conc.Sync Methods (>>=) :: STM a -> (a -> STM b) -> STM b Source # (>>) :: STM a -> STM b -> STM b Source # return :: a -> STM a Source # fail :: String -> STM a Source #
Monad First | Since: base-4.8.0.0
Instance details Defined in Data.Monoid Methods (>>=) :: First a -> (a -> First b) -> First b Source # (>>) :: First a -> First b -> First b Source # return :: a -> First a Source # fail :: String -> First a Source #
Monad Last | Since: base-4.8.0.0
Instance details Defined in Data.Monoid Methods (>>=) :: Last a -> (a -> Last b) -> Last b Source # (>>) :: Last a -> Last b -> Last b Source # return :: a -> Last a Source # fail :: String -> Last a Source #
Monad Dual | Since: base-4.8.0.0
Instance details Defined in Data.Semigroup.Internal Methods (>>=) :: Dual a -> (a -> Dual b) -> Dual b Source # (>>) :: Dual a -> Dual b -> Dual b Source # return :: a -> Dual a Source # fail :: String -> Dual a Source #
Monad Sum | Since: base-4.8.0.0
Instance details Defined in Data.Semigroup.Internal Methods (>>=) :: Sum a -> (a -> Sum b) -> Sum b Source # (>>) :: Sum a -> Sum b -> Sum b Source # return :: a -> Sum a Source # fail :: String -> Sum a Source #
Monad Product | Since: base-4.8.0.0
Instance details Defined in Data.Semigroup.Internal Methods (>>=) :: Product a -> (a -> Product b) -> Product b Source # (>>) :: Product a -> Product b -> Product b Source # return :: a -> Product a Source # fail :: String -> Product a Source #
Monad ReadPrec | Since: base-2.1
Instance details Defined in Text.ParserCombinators.ReadPrec Methods (>>=) :: ReadPrec a -> (a -> ReadPrec b) -> ReadPrec b Source # (>>) :: ReadPrec a -> ReadPrec b -> ReadPrec b Source # return :: a -> ReadPrec a Source # fail :: String -> ReadPrec a Source #
Monad ReadP | Since: base-2.1
Instance details Defined in Text.ParserCombinators.ReadP Methods (>>=) :: ReadP a -> (a -> ReadP b) -> ReadP b Source # (>>) :: ReadP a -> ReadP b -> ReadP b Source # return :: a -> ReadP a Source # fail :: String -> ReadP a Source #
Monad NonEmpty | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods (>>=) :: NonEmpty a -> (a -> NonEmpty b) -> NonEmpty b Source # (>>) :: NonEmpty a -> NonEmpty b -> NonEmpty b Source # return :: a -> NonEmpty a Source # fail :: String -> NonEmpty a Source #
Monad P | Since: base-2.1
Instance details Defined in Text.ParserCombinators.ReadP Methods (>>=) :: P a -> (a -> P b) -> P b Source # (>>) :: P a -> P b -> P b Source # return :: a -> P a Source # fail :: String -> P a Source #
Monad (Either e) | Since: base-4.4.0.0
Instance details Defined in Data.Either Methods (>>=) :: Either e a -> (a -> Either e b) -> Either e b Source # (>>) :: Either e a -> Either e b -> Either e b Source # return :: a -> Either e a Source # fail :: String -> Either e a Source #
Monoid a => Monad ((,) a) | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods (>>=) :: (a, a0) -> (a0 -> (a, b)) -> (a, b) Source # (>>) :: (a, a0) -> (a, b) -> (a, b) Source # return :: a0 -> (a, a0) Source # fail :: String -> (a, a0) Source #
Monad (ST s) | Since: base-2.1
Instance details Defined in GHC.ST Methods (>>=) :: ST s a -> (a -> ST s b) -> ST s b Source # (>>) :: ST s a -> ST s b -> ST s b Source # return :: a -> ST s a Source # fail :: String -> ST s a Source #
Monad (ST s) | Since: base-2.1
Instance details Defined in Control.Monad.ST.Lazy.Imp Methods (>>=) :: ST s a -> (a -> ST s b) -> ST s b Source # (>>) :: ST s a -> ST s b -> ST s b Source # return :: a -> ST s a Source # fail :: String -> ST s a Source #
Monad m => Monad (WrappedMonad m) | Since: base-4.7.0.0
Instance details Defined in Control.Applicative Methods (>>=) :: WrappedMonad m a -> (a -> WrappedMonad m b) -> WrappedMonad m b Source # (>>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b Source # return :: a -> WrappedMonad m a Source # fail :: String -> WrappedMonad m a Source #
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0
Instance details Defined in Data.Proxy Methods (>>=) :: Proxy a -> (a -> Proxy b) -> Proxy b Source # (>>) :: Proxy a -> Proxy b -> Proxy b Source # return :: a -> Proxy a Source # fail :: String -> Proxy a Source #
Monad f => Monad (Ap f) | Since: base-4.12.0.0
Instance details Defined in Data.Monoid Methods (>>=) :: Ap f a -> (a -> Ap f b) -> Ap f b Source # (>>) :: Ap f a -> Ap f b -> Ap f b Source # return :: a -> Ap f a Source # fail :: String -> Ap f a Source #
Monad f => Monad (Alt f) | Since: base-4.8.0.0
Instance details Defined in Data.Semigroup.Internal Methods (>>=) :: Alt f a -> (a -> Alt f b) -> Alt f b Source # (>>) :: Alt f a -> Alt f b -> Alt f b Source # return :: a -> Alt f a Source # fail :: String -> Alt f a Source #
Monad ((->) r :: Type -> Type) | Since: base-2.1
Instance details Defined in GHC.Base Methods (>>=) :: (r -> a) -> (a -> r -> b) -> r -> b Source # (>>) :: (r -> a) -> (r -> b) -> r -> b Source # return :: a -> r -> a Source # fail :: String -> r -> a Source #
(Monad f, Monad g) => Monad (Product f g) | Since: base-4.9.0.0
Instance details Defined in Data.Functor.Product Methods (>>=) :: Product f g a -> (a -> Product f g b) -> Product f g b Source # (>>) :: Product f g a -> Product f g b -> Product f g b Source # return :: a -> Product f g a Source # fail :: String -> Product f g a Source #

class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where Source #

Monads that also support choice and failure.

Minimal complete definition

Nothing

Methods

mzero :: m a Source #

The identity of `mplus`. It should also satisfy the equations

    mzero >>= f  =  mzero
    v >> mzero   =  mzero

The default definition is

    mzero = empty

mplus :: m a -> m a -> m a Source #

An associative operation. The default definition is

    mplus = (<|>)

Instances

MonadPlus [] | Since: base-2.1
Instance details Defined in GHC.Base Methods mzero :: [a] Source # mplus :: [a] -> [a] -> [a] Source #
MonadPlus Maybe | Since: base-2.1
Instance details Defined in GHC.Base Methods mzero :: Maybe a Source # mplus :: Maybe a -> Maybe a -> Maybe a Source #
MonadPlus IO | Since: base-4.9.0.0
Instance details Defined in GHC.Base Methods mzero :: IO a Source # mplus :: IO a -> IO a -> IO a Source #
MonadPlus Option | Since: base-4.9.0.0
Instance details Defined in Data.Semigroup Methods mzero :: Option a Source # mplus :: Option a -> Option a -> Option a Source #
MonadPlus STM | Since: base-4.3.0.0
Instance details Defined in GHC.Conc.Sync Methods mzero :: STM a Source # mplus :: STM a -> STM a -> STM a Source #
MonadPlus ReadPrec | Since: base-2.1
Instance details Defined in Text.ParserCombinators.ReadPrec Methods mzero :: ReadPrec a Source # mplus :: ReadPrec a -> ReadPrec a -> ReadPrec a Source #
MonadPlus ReadP | Since: base-2.1
Instance details Defined in Text.ParserCombinators.ReadP Methods mzero :: ReadP a Source # mplus :: ReadP a -> ReadP a -> ReadP a Source #
MonadPlus P | Since: base-2.1
Instance details Defined in Text.ParserCombinators.ReadP Methods mzero :: P a Source # mplus :: P a -> P a -> P a Source #
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in Data.Proxy Methods mzero :: Proxy a Source # mplus :: Proxy a -> Proxy a -> Proxy a Source #
MonadPlus f => MonadPlus (Ap f) | Since: base-4.12.0.0
Instance details Defined in Data.Monoid Methods mzero :: Ap f a Source # mplus :: Ap f a -> Ap f a -> Ap f a Source #
MonadPlus f => MonadPlus (Alt f) | Since: base-4.8.0.0
Instance details Defined in Data.Semigroup.Internal Methods mzero :: Alt f a Source # mplus :: Alt f a -> Alt f a -> Alt f a Source #
(MonadPlus f, MonadPlus g) => MonadPlus (Product f g) | Since: base-4.9.0.0
Instance details Defined in Data.Functor.Product Methods mzero :: Product f g a Source # mplus :: Product f g a -> Product f g a -> Product f g a Source #