Control.Monad.Compat

base-compat-0.9.3: A compatibility layer for base

Safe Haskell | Safe
Language | Haskell98

Control.Monad.Compat

Synopsis

- class Applicative m => Monad m 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 where
  - mzero :: m a
  - mplus :: m a -> m a -> m a

# Documentation

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:

-     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

(>>=)

Instances

Monad [] |
Methods (>>=) :: [a] -> (a -> [b]) -> [b] # (>>) :: [a] -> [b] -> [b] # return :: a -> [a] # fail :: String -> [a] #
Monad Maybe |
Methods (>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b # (>>) :: Maybe a -> Maybe b -> Maybe b # return :: a -> Maybe a # fail :: String -> Maybe a #
Monad IO |
Methods (>>=) :: IO a -> (a -> IO b) -> IO b # (>>) :: IO a -> IO b -> IO b # return :: a -> IO a # fail :: String -> IO a #
Monad U1 |
Methods (>>=) :: U1 a -> (a -> U1 b) -> U1 b # (>>) :: U1 a -> U1 b -> U1 b # return :: a -> U1 a # fail :: String -> U1 a #
Monad Par1 |
Methods (>>=) :: Par1 a -> (a -> Par1 b) -> Par1 b # (>>) :: Par1 a -> Par1 b -> Par1 b # return :: a -> Par1 a # fail :: String -> Par1 a #
Monad P |
Methods (>>=) :: P a -> (a -> P b) -> P b # (>>) :: P a -> P b -> P b # return :: a -> P a # fail :: String -> P a #
Monad Complex |
Methods (>>=) :: Complex a -> (a -> Complex b) -> Complex b # (>>) :: Complex a -> Complex b -> Complex b # return :: a -> Complex a # fail :: String -> Complex a #
Monad STM |
Methods (>>=) :: STM a -> (a -> STM b) -> STM b # (>>) :: STM a -> STM b -> STM b # return :: a -> STM a # fail :: String -> STM a #
Monad Dual |
Methods (>>=) :: Dual a -> (a -> Dual b) -> Dual b # (>>) :: Dual a -> Dual b -> Dual b # return :: a -> Dual a # fail :: String -> Dual a #
Monad Sum |
Methods (>>=) :: Sum a -> (a -> Sum b) -> Sum b # (>>) :: Sum a -> Sum b -> Sum b # return :: a -> Sum a # fail :: String -> Sum a #
Monad Product |
Methods (>>=) :: Product a -> (a -> Product b) -> Product b # (>>) :: Product a -> Product b -> Product b # return :: a -> Product a # fail :: String -> Product a #
Monad First |
Methods (>>=) :: First a -> (a -> First b) -> First b # (>>) :: First a -> First b -> First b # return :: a -> First a # fail :: String -> First a #
Monad Last |
Methods (>>=) :: Last a -> (a -> Last b) -> Last b # (>>) :: Last a -> Last b -> Last b # return :: a -> Last a # fail :: String -> Last a #
Monad ReadPrec |
Methods (>>=) :: ReadPrec a -> (a -> ReadPrec b) -> ReadPrec b # (>>) :: ReadPrec a -> ReadPrec b -> ReadPrec b # return :: a -> ReadPrec a # fail :: String -> ReadPrec a #
Monad ReadP |
Methods (>>=) :: ReadP a -> (a -> ReadP b) -> ReadP b # (>>) :: ReadP a -> ReadP b -> ReadP b # return :: a -> ReadP a # fail :: String -> ReadP a #
Monad ((->) r) |
Methods (>>=) :: (r -> a) -> (a -> r -> b) -> r -> b # (>>) :: (r -> a) -> (r -> b) -> r -> b # return :: a -> r -> a # fail :: String -> r -> a #
Monad (Either e) |
Methods (>>=) :: Either e a -> (a -> Either e b) -> Either e b # (>>) :: Either e a -> Either e b -> Either e b # return :: a -> Either e a # fail :: String -> Either e a #
Monad f => Monad (Rec1 f) |
Methods (>>=) :: Rec1 f a -> (a -> Rec1 f b) -> Rec1 f b # (>>) :: Rec1 f a -> Rec1 f b -> Rec1 f b # return :: a -> Rec1 f a # fail :: String -> Rec1 f a #
Monoid a => Monad ((,) a) |
Methods (>>=) :: (a, a) -> (a -> (a, b)) -> (a, b) # (>>) :: (a, a) -> (a, b) -> (a, b) # return :: a -> (a, a) # fail :: String -> (a, a) #
Monad (ST s) |
Methods (>>=) :: ST s a -> (a -> ST s b) -> ST s b # (>>) :: ST s a -> ST s b -> ST s b # return :: a -> ST s a # fail :: String -> ST s a #
Monad (ST s) |
Methods (>>=) :: ST s a -> (a -> ST s b) -> ST s b # (>>) :: ST s a -> ST s b -> ST s b # return :: a -> ST s a # fail :: String -> ST s a #
Monad m => Monad (WrappedMonad m) |
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 # fail :: String -> WrappedMonad m a #
Monad (Proxy *) |
Methods (>>=) :: Proxy * a -> (a -> Proxy * b) -> Proxy * b # (>>) :: Proxy * a -> Proxy * b -> Proxy * b # return :: a -> Proxy * a # fail :: String -> Proxy * a #
(Monad f, Monad g) => Monad ((:*:) f g) |
Methods (>>=) :: (f :*: g) a -> (a -> (f :*: g) b) -> (f :*: g) b # (>>) :: (f :*: g) a -> (f :*: g) b -> (f :*: g) b # return :: a -> (f :*: g) a # fail :: String -> (f :*: g) a #
Monad f => Monad (Alt * f) |
Methods (>>=) :: Alt * f a -> (a -> Alt * f b) -> Alt * f b # (>>) :: Alt * f a -> Alt * f b -> Alt * f b # return :: a -> Alt * f a # fail :: String -> Alt * f a #
Monad f => Monad (M1 i c f) |
Methods (>>=) :: M1 i c f a -> (a -> M1 i c f b) -> M1 i c f b # (>>) :: M1 i c f a -> M1 i c f b -> M1 i c f b # return :: a -> M1 i c f a # fail :: String -> M1 i c f a #

class (Alternative m, Monad m) => MonadPlus m where #

Monads that also support choice and failure.

Minimal complete definition

Nothing

Instances

MonadPlus [] |
Methods mzero :: [a] # mplus :: [a] -> [a] -> [a] #
MonadPlus Maybe |
Methods mzero :: Maybe a # mplus :: Maybe a -> Maybe a -> Maybe a #
MonadPlus IO |
Methods mzero :: IO a # mplus :: IO a -> IO a -> IO a #
MonadPlus U1 |
Methods mzero :: U1 a # mplus :: U1 a -> U1 a -> U1 a #
MonadPlus P |
Methods mzero :: P a # mplus :: P a -> P a -> P a #
MonadPlus STM |
Methods mzero :: STM a # mplus :: STM a -> STM a -> STM a #
MonadPlus ReadPrec |
Methods mzero :: ReadPrec a # mplus :: ReadPrec a -> ReadPrec a -> ReadPrec a #
MonadPlus ReadP |
Methods mzero :: ReadP a # mplus :: ReadP a -> ReadP a -> ReadP a #
MonadPlus f => MonadPlus (Rec1 f) |
Methods mzero :: Rec1 f a # mplus :: Rec1 f a -> Rec1 f a -> Rec1 f a #
MonadPlus (Proxy *) |
Methods mzero :: Proxy * a # mplus :: Proxy * a -> Proxy * a -> Proxy * a #
(MonadPlus f, MonadPlus g) => MonadPlus ((:*:) f g) |
Methods mzero :: (f :*: g) a # mplus :: (f :*: g) a -> (f :*: g) a -> (f :*: g) a #
MonadPlus f => MonadPlus (Alt * f) |
Methods mzero :: Alt * f a # mplus :: Alt * f a -> Alt * f a -> Alt * f a #
MonadPlus f => MonadPlus (M1 i c f) |
Methods mzero :: M1 i c f a # mplus :: M1 i c f a -> M1 i c f a -> M1 i c f a #