foundation-0.0.3: Alternative prelude with batteries and no dependencies

Safe Haskell | None
Language | Haskell2010

Foundation.Monad

Synopsis

- class Monad m => MonadIO m where
  - liftIO :: IO a -> m a
- class Monad m => MonadFailure m where
  - type Failure m
- class Monad m => MonadThrow m where
- class MonadThrow m => MonadCatch m where
- class MonadTrans trans where

# Documentation

class Monad m => MonadIO m where #

Monads in which `IO` computations may be embedded. Any monad built by applying a sequence of monad transformers to the `IO` monad will be an instance of this class.

Instances should satisfy the following laws, which state that `liftIO` is a transformer of monads:

-     liftIO . return = return

-     liftIO (m >>= f) = liftIO m >>= (liftIO . f)

Instances

MonadIO IO |
Methods liftIO :: IO a -> IO a #
MonadIO m => MonadIO (ReaderT r m) # |
Methods liftIO :: IO a -> ReaderT r m a #
(Functor m, MonadIO m) => MonadIO (StateT s m) # |
Methods liftIO :: IO a -> StateT s m a #

class Monad m => MonadFailure m where #

Monad that can represent failure

Similar to MonadFail but with a parametrized Failure linked to the Monad

Minimal complete definition

mFail

Associated Types

type Failure m #

The associated type with the MonadFailure, representing what failure can be encoded in this monad

Methods

mFail :: Failure m -> m () #

Raise a Failure through a monad.

Instances

MonadFailure Maybe # |
Associated Types type Failure (Maybe :: * -> *) :: * # Methods mFail :: Failure Maybe -> Maybe () #
MonadFailure (Either a) # |
Associated Types type Failure (Either a :: * -> *) :: * # Methods mFail :: Failure (Either a) -> Either a () #
MonadFailure m => MonadFailure (ReaderT r m) # |
Associated Types type Failure (ReaderT r m :: * -> *) :: * # Methods mFail :: Failure (ReaderT r m) -> ReaderT r m () #
(Functor m, MonadFailure m) => MonadFailure (StateT s m) # |
Associated Types type Failure (StateT s m :: * -> *) :: * # Methods mFail :: Failure (StateT s m) -> StateT s m () #

class Monad m => MonadThrow m where #

Monad that can throw exception

Minimal complete definition

throw

Methods

throw :: Exception e => e -> m a #

Throw immediatity an exception. Only a `MonadCatch` monad will be able to catch the exception using `catch`

Instances

MonadThrow IO # |
Methods throw :: Exception e => e -> IO a #
MonadThrow m => MonadThrow (ReaderT r m) # |
Methods throw :: Exception e => e -> ReaderT r m a #
(Functor m, MonadThrow m) => MonadThrow (StateT s m) # |
Methods throw :: Exception e => e -> StateT s m a #

class MonadThrow m => MonadCatch m where #

Monad that can catch exception

Minimal complete definition

catch

Methods

catch :: Exception e => m a -> (e -> m a) -> m a #

Instances

MonadCatch IO # |
Methods catch :: Exception e => IO a -> (e -> IO a) -> IO a #
MonadCatch m => MonadCatch (ReaderT r m) # |
Methods catch :: Exception e => ReaderT r m a -> (e -> ReaderT r m a) -> ReaderT r m a #
(Functor m, MonadCatch m) => MonadCatch (StateT s m) # |
Methods catch :: Exception e => StateT s m a -> (e -> StateT s m a) -> StateT s m a #

class MonadTrans trans where #

Basic Transformer class

Minimal complete definition

lift

Methods

lift :: Monad m => m a -> trans m a #

Lift a computation from an inner monad to the current transformer monad

Instances

MonadTrans (ReaderT r) # |
Methods lift :: Monad m => m a -> ReaderT r m a #
MonadTrans (StateT s) # |
Methods lift :: Monad m => m a -> StateT s m a #