base-compat-0.14.1: A compatibility layer for base

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
  - mzero :: m a
  - mplus :: m a -> m a -> m a

# Documentation

module Control.Monad

module Control.Monad.Fail

class Applicative m => Monad (m :: Type -> Type) 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:

Left identity
  ``return` a `>>=` 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:

-     pure = return

-     m1 <*> m2 = m1 >>= (\x1 -> m2 >>= (\x2 -> return (x1 x2)))

The above laws imply:

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

-     (>>) = (*>)

and that `pure` and (`<*>`) satisfy the applicative functor laws.

The instances of `Monad` for `List`, `Maybe` and `IO` defined in the Prelude satisfy these laws.

Minimal complete definition

(>>=)

#### Instances

Instances details

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 #
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 #
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 #
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 #
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 #
Monad NonEmpty | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Base Methods (>>=) :: NonEmpty a -> (a -> NonEmpty b) -> NonEmpty b Source # (>>) :: NonEmpty a -> NonEmpty b -> NonEmpty b Source # return :: a -> NonEmpty a Source #
Monad STM | Since: base-4.3.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods (>>=) :: STM a -> (a -> STM b) -> STM b Source # (>>) :: STM a -> STM b -> STM b Source # return :: a -> STM a Source #
Monad Identity | Since: base-4.8.0.0
Instance details Defined in GHC.Internal.Data.Functor.Identity Methods (>>=) :: Identity a -> (a -> Identity b) -> Identity b Source # (>>) :: Identity a -> Identity b -> Identity b Source # return :: a -> Identity a Source #
Monad First | Since: base-4.8.0.0
Instance details Defined in GHC.Internal.Data.Monoid Methods (>>=) :: First a -> (a -> First b) -> First b Source # (>>) :: First a -> First b -> First b Source # return :: a -> First a Source #
Monad Last | Since: base-4.8.0.0
Instance details Defined in GHC.Internal.Data.Monoid Methods (>>=) :: Last a -> (a -> Last b) -> Last b Source # (>>) :: Last a -> Last b -> Last b Source # return :: a -> Last a Source #
Monad Dual | Since: base-4.8.0.0
Instance details Defined in GHC.Internal.Data.Semigroup.Internal Methods (>>=) :: Dual a -> (a -> Dual b) -> Dual b Source # (>>) :: Dual a -> Dual b -> Dual b Source # return :: a -> Dual a Source #
Monad Product | Since: base-4.8.0.0
Instance details Defined in GHC.Internal.Data.Semigroup.Internal Methods (>>=) :: Product a -> (a -> Product b) -> Product b Source # (>>) :: Product a -> Product b -> Product b Source # return :: a -> Product a Source #
Monad Sum | Since: base-4.8.0.0
Instance details Defined in GHC.Internal.Data.Semigroup.Internal Methods (>>=) :: Sum a -> (a -> Sum b) -> Sum b Source # (>>) :: Sum a -> Sum b -> Sum b Source # return :: a -> Sum a Source #
Monad Par1 | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods (>>=) :: Par1 a -> (a -> Par1 b) -> Par1 b Source # (>>) :: Par1 a -> Par1 b -> Par1 b Source # return :: a -> Par1 a Source #
Monad P | Since: base-2.1
Instance details Defined in GHC.Internal.Text.ParserCombinators.ReadP Methods (>>=) :: P a -> (a -> P b) -> P b Source # (>>) :: P a -> P b -> P b Source # return :: a -> P a Source #
Monad ReadP | Since: base-2.1
Instance details Defined in GHC.Internal.Text.ParserCombinators.ReadP Methods (>>=) :: ReadP a -> (a -> ReadP b) -> ReadP b Source # (>>) :: ReadP a -> ReadP b -> ReadP b Source # return :: a -> ReadP a Source #
Monad ReadPrec | Since: base-2.1
Instance details Defined in GHC.Internal.Text.ParserCombinators.ReadPrec Methods (>>=) :: ReadPrec a -> (a -> ReadPrec b) -> ReadPrec b Source # (>>) :: ReadPrec a -> ReadPrec b -> ReadPrec b Source # return :: a -> ReadPrec a Source #
Monad IO | Since: base-2.1
Instance details Defined in GHC.Internal.Base Methods (>>=) :: IO a -> (a -> IO b) -> IO b Source # (>>) :: IO a -> IO b -> IO b Source # return :: a -> IO a Source #
Monad Maybe | Since: base-2.1
Instance details Defined in GHC.Internal.Base Methods (>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b Source # (>>) :: Maybe a -> Maybe b -> Maybe b Source # return :: a -> Maybe a Source #
Monad Solo | Since: base-4.15
Instance details Defined in GHC.Internal.Base Methods (>>=) :: Solo a -> (a -> Solo b) -> Solo b Source # (>>) :: Solo a -> Solo b -> Solo b Source # return :: a -> Solo a Source #
Monad [] | Since: base-2.1
Instance details Defined in GHC.Internal.Base Methods (>>=) :: [a] -> (a -> [b]) -> [b] Source # (>>) :: [a] -> [b] -> [b] Source # return :: a -> [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 #
ArrowApply a => Monad (ArrowMonad a) | Since: base-2.1
Instance details Defined in GHC.Internal.Control.Arrow Methods (>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b Source # (>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b Source # return :: a0 -> ArrowMonad a a0 Source #
Monad (ST s) | Since: base-2.1
Instance details Defined in GHC.Internal.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 #
Monad (Either e) | Since: base-4.4.0.0
Instance details Defined in GHC.Internal.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 #
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0
Instance details Defined in GHC.Internal.Data.Proxy Methods (>>=) :: Proxy a -> (a -> Proxy b) -> Proxy b Source # (>>) :: Proxy a -> Proxy b -> Proxy b Source # return :: a -> Proxy a Source #
Monad (U1 :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods (>>=) :: U1 a -> (a -> U1 b) -> U1 b Source # (>>) :: U1 a -> U1 b -> U1 b Source # return :: a -> U1 a Source #
Monad (ST s) | Since: base-2.1
Instance details Defined in GHC.Internal.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 #
Monoid a => Monad ((,) a) | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Base Methods (>>=) :: (a, a0) -> (a0 -> (a, b)) -> (a, b) Source # (>>) :: (a, a0) -> (a, b) -> (a, b) Source # return :: a0 -> (a, a0) Source #
Monad m => Monad (Kleisli m a) | Since: base-4.14.0.0
Instance details Defined in GHC.Internal.Control.Arrow Methods (>>=) :: Kleisli m a a0 -> (a0 -> Kleisli m a b) -> Kleisli m a b Source # (>>) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a b Source # return :: a0 -> Kleisli m a a0 Source #
Monad f => Monad (Ap f) | Since: base-4.12.0.0
Instance details Defined in GHC.Internal.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 #
Monad f => Monad (Alt f) | Since: base-4.8.0.0
Instance details Defined in GHC.Internal.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 #
Monad f => Monad (Rec1 f) | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods (>>=) :: Rec1 f a -> (a -> Rec1 f b) -> Rec1 f b Source # (>>) :: Rec1 f a -> Rec1 f b -> Rec1 f b Source # return :: a -> Rec1 f a Source #
(Monoid a, Monoid b) => Monad ((,,) a b) | Since: base-4.14.0.0
Instance details Defined in GHC.Internal.Base Methods (>>=) :: (a, b, a0) -> (a0 -> (a, b, b0)) -> (a, b, b0) Source # (>>) :: (a, b, a0) -> (a, b, b0) -> (a, b, b0) Source # return :: a0 -> (a, b, a0) 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 #
(Monad f, Monad g) => Monad (f :*: g) | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods (>>=) :: (f :*: g) a -> (a -> (f :*: g) b) -> (f :*: g) b Source # (>>) :: (f :*: g) a -> (f :*: g) b -> (f :*: g) b Source # return :: a -> (f :*: g) a Source #
(Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) | Since: base-4.14.0.0
Instance details Defined in GHC.Internal.Base Methods (>>=) :: (a, b, c, a0) -> (a0 -> (a, b, c, b0)) -> (a, b, c, b0) Source # (>>) :: (a, b, c, a0) -> (a, b, c, b0) -> (a, b, c, b0) Source # return :: a0 -> (a, b, c, a0) Source #
Monad ((->) r) | Since: base-2.1
Instance details Defined in GHC.Internal.Base Methods (>>=) :: (r -> a) -> (a -> r -> b) -> r -> b Source # (>>) :: (r -> a) -> (r -> b) -> r -> b Source # return :: a -> r -> a Source #
Monad f => Monad (M1 i c f) | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods (>>=) :: M1 i c f a -> (a -> M1 i c f b) -> M1 i c f b Source # (>>) :: M1 i c f a -> M1 i c f b -> M1 i c f b Source # return :: a -> M1 i c f a Source #

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

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

fail

#### Instances

Instances details

MonadFail P | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Text.ParserCombinators.ReadP Methods fail :: String -> P a Source #
MonadFail ReadP | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Text.ParserCombinators.ReadP Methods fail :: String -> ReadP a Source #
MonadFail ReadPrec | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Text.ParserCombinators.ReadPrec Methods fail :: String -> ReadPrec a Source #
MonadFail IO | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Control.Monad.Fail Methods fail :: String -> IO a Source #
MonadFail Maybe | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Control.Monad.Fail Methods fail :: String -> Maybe a Source #
MonadFail [] | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Control.Monad.Fail Methods fail :: String -> [a] Source #
MonadFail f => MonadFail (Ap f) | Since: base-4.12.0.0
Instance details Defined in GHC.Internal.Data.Monoid Methods fail :: String -> Ap f a Source #

fail :: MonadFail m => String -> m 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

Instances details

MonadPlus STM | Takes the first non-`retry`ing `STM` action. Since: base-4.3.0.0
Instance details Defined in GHC.Internal.Conc.Sync Methods mzero :: STM a Source # mplus :: STM a -> STM a -> STM a Source #
MonadPlus P | Since: base-2.1
Instance details Defined in GHC.Internal.Text.ParserCombinators.ReadP Methods mzero :: P a Source # mplus :: P a -> P a -> P a Source #
MonadPlus ReadP | Since: base-2.1
Instance details Defined in GHC.Internal.Text.ParserCombinators.ReadP Methods mzero :: ReadP a Source # mplus :: ReadP a -> ReadP a -> ReadP a Source #
MonadPlus ReadPrec | Since: base-2.1
Instance details Defined in GHC.Internal.Text.ParserCombinators.ReadPrec Methods mzero :: ReadPrec a Source # mplus :: ReadPrec a -> ReadPrec a -> ReadPrec a Source #
MonadPlus IO | Takes the first non-throwing `IO` action's result. `mzero` throws an exception. Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Base Methods mzero :: IO a Source # mplus :: IO a -> IO a -> IO a Source #
MonadPlus Maybe | Picks the leftmost `Just` value, or, alternatively, `Nothing`. Since: base-2.1
Instance details Defined in GHC.Internal.Base Methods mzero :: Maybe a Source # mplus :: Maybe a -> Maybe a -> Maybe a Source #
MonadPlus [] | Combines lists by concatenation, starting from the empty list. Since: base-2.1
Instance details Defined in GHC.Internal.Base Methods mzero :: [a] Source # mplus :: [a] -> [a] -> [a] Source #
(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) | Since: base-4.6.0.0
Instance details Defined in GHC.Internal.Control.Arrow Methods mzero :: ArrowMonad a a0 Source # mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 Source #
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Data.Proxy Methods mzero :: Proxy a Source # mplus :: Proxy a -> Proxy a -> Proxy a Source #
MonadPlus (U1 :: Type -> Type) | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods mzero :: U1 a Source # mplus :: U1 a -> U1 a -> U1 a Source #
MonadPlus m => MonadPlus (Kleisli m a) | Since: base-4.14.0.0
Instance details Defined in GHC.Internal.Control.Arrow Methods mzero :: Kleisli m a a0 Source # mplus :: Kleisli m a a0 -> Kleisli m a a0 -> Kleisli m a a0 Source #
MonadPlus f => MonadPlus (Ap f) | Since: base-4.12.0.0
Instance details Defined in GHC.Internal.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 GHC.Internal.Data.Semigroup.Internal Methods mzero :: Alt f a Source # mplus :: Alt f a -> Alt f a -> Alt f a Source #
MonadPlus f => MonadPlus (Rec1 f) | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods mzero :: Rec1 f a Source # mplus :: Rec1 f a -> Rec1 f a -> Rec1 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 #
(MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods mzero :: (f :*: g) a Source # mplus :: (f :*: g) a -> (f :*: g) a -> (f :*: g) a Source #
MonadPlus f => MonadPlus (M1 i c f) | Since: base-4.9.0.0
Instance details Defined in GHC.Internal.Generics Methods mzero :: M1 i c f a Source # mplus :: M1 i c f a -> M1 i c f a -> M1 i c f a Source #