Control.Monad.Catch.Pure

exceptions-0.10.3: Extensible optionally-pure exceptions

Copyright | (C) Edward Kmett 2013-2015 (c) Google Inc. 2012
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | experimental
Portability | non-portable
Safe Haskell | Trustworthy
Language | Haskell98

Control.Monad.Catch.Pure

Contents

- Transformer
- Typeclass

Description

This module supplies a 'pure' monad transformer that can be used for mock-testing code that throws exceptions, so long as those exceptions are always thrown with `throwM`.

Do not mix `CatchT` with `IO`. Choose one or the other for the bottom of your transformer stack!

Synopsis

- newtype CatchT m a = CatchT {
  - runCatchT :: m (Either SomeException a)
  }
- type Catch = CatchT Identity
- runCatch :: Catch a -> Either SomeException a
- mapCatchT :: (m (Either SomeException a) -> n (Either SomeException b)) -> CatchT m a -> CatchT n b
- module Control.Monad.Catch

# Transformer

The `transformers`-style monad transfomer

newtype CatchT m a Source #

Add `Exception` handling abilities to a `Monad`.

This should never be used in combination with `IO`. Think of `CatchT` as an alternative base monad for use with mocking code that solely throws exceptions via `throwM`.

Note: that `IO` monad has these abilities already, so stacking `CatchT` on top of it does not add any value and can possibly be confusing:

    >>> (error "Hello!" :: IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)
    Hello!

    >>> runCatchT $ (error "Hello!" :: CatchT IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)
    *** Exception: Hello!

    >>> runCatchT $ (throwM (ErrorCall "Hello!") :: CatchT IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)
    Hello!

Constructors

CatchT |
Fields runCatchT :: m (Either SomeException a)

#### Instances

Instances details

MonadTrans CatchT # |
Instance details Defined in Control.Monad.Catch.Pure Methods lift :: Monad m => m a -> CatchT m a Source #
MonadRWS r w s m => MonadRWS r w s (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure
MonadWriter w m => MonadWriter w (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods writer :: (a, w) -> CatchT m a Source # tell :: w -> CatchT m () Source # listen :: CatchT m a -> CatchT m (a, w) Source # pass :: CatchT m (a, w -> w) -> CatchT m a Source #
MonadState s m => MonadState s (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods get :: CatchT m s Source # put :: s -> CatchT m () Source # state :: (s -> (a, s)) -> CatchT m a Source #
MonadReader e m => MonadReader e (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods ask :: CatchT m e Source # local :: (e -> e) -> CatchT m a -> CatchT m a Source # reader :: (e -> a) -> CatchT m a Source #
Monad m => Monad (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods (>>=) :: CatchT m a -> (a -> CatchT m b) -> CatchT m b Source # (>>) :: CatchT m a -> CatchT m b -> CatchT m b Source # return :: a -> CatchT m a Source #
Monad m => Functor (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods fmap :: (a -> b) -> CatchT m a -> CatchT m b Source # (<$) :: a -> CatchT m b -> CatchT m a Source #
MonadFix m => MonadFix (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods mfix :: (a -> CatchT m a) -> CatchT m a Source #
Monad m => MonadFail (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods fail :: String -> CatchT m a Source #
Monad m => Applicative (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods pure :: a -> CatchT m a Source # (<*>) :: CatchT m (a -> b) -> CatchT m a -> CatchT m b Source # liftA2 :: (a -> b -> c) -> CatchT m a -> CatchT m b -> CatchT m c Source # (*>) :: CatchT m a -> CatchT m b -> CatchT m b Source # (<*) :: CatchT m a -> CatchT m b -> CatchT m a Source #
Foldable m => Foldable (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods fold :: Monoid m0 => CatchT m m0 -> m0 Source # foldMap :: Monoid m0 => (a -> m0) -> CatchT m a -> m0 Source # foldMap' :: Monoid m0 => (a -> m0) -> CatchT m a -> m0 Source # foldr :: (a -> b -> b) -> b -> CatchT m a -> b Source # foldr' :: (a -> b -> b) -> b -> CatchT m a -> b Source # foldl :: (b -> a -> b) -> b -> CatchT m a -> b Source # foldl' :: (b -> a -> b) -> b -> CatchT m a -> b Source # foldr1 :: (a -> a -> a) -> CatchT m a -> a Source # foldl1 :: (a -> a -> a) -> CatchT m a -> a Source # toList :: CatchT m a -> [a] Source # null :: CatchT m a -> Bool Source # length :: CatchT m a -> Int Source # elem :: Eq a => a -> CatchT m a -> Bool Source # maximum :: Ord a => CatchT m a -> a Source # minimum :: Ord a => CatchT m a -> a Source # sum :: Num a => CatchT m a -> a Source # product :: Num a => CatchT m a -> a Source #
(Monad m, Traversable m) => Traversable (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods traverse :: Applicative f => (a -> f b) -> CatchT m a -> f (CatchT m b) Source # sequenceA :: Applicative f => CatchT m (f a) -> f (CatchT m a) Source # mapM :: Monad m0 => (a -> m0 b) -> CatchT m a -> m0 (CatchT m b) Source # sequence :: Monad m0 => CatchT m (m0 a) -> m0 (CatchT m a) Source #
MonadIO m => MonadIO (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods liftIO :: IO a -> CatchT m a Source #
Monad m => Alternative (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods empty :: CatchT m a Source # (<|>) :: CatchT m a -> CatchT m a -> CatchT m a Source # some :: CatchT m a -> CatchT m [a] Source # many :: CatchT m a -> CatchT m [a] Source #
Monad m => MonadPlus (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods mzero :: CatchT m a Source # mplus :: CatchT m a -> CatchT m a -> CatchT m a Source #
Monad m => MonadMask (CatchT m) # | Note: This instance is only valid if the underlying monad has a single exit point! For example, `IO` or `Either` would be invalid base monads, but `Reader` or `State` would be acceptable.
Instance details Defined in Control.Monad.Catch.Pure Methods mask :: ((forall a. CatchT m a -> CatchT m a) -> CatchT m b) -> CatchT m b Source # uninterruptibleMask :: ((forall a. CatchT m a -> CatchT m a) -> CatchT m b) -> CatchT m b Source # generalBracket :: CatchT m a -> (a -> ExitCase b -> CatchT m c) -> (a -> CatchT m b) -> CatchT m (b, c) Source #
Monad m => MonadCatch (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods catch :: Exception e => CatchT m a -> (e -> CatchT m a) -> CatchT m a Source #
Monad m => MonadThrow (CatchT m) # |
Instance details Defined in Control.Monad.Catch.Pure Methods throwM :: Exception e => e -> CatchT m a Source #

type Catch = CatchT Identity Source #

runCatch :: Catch a -> Either SomeException a Source #

mapCatchT :: (m (Either SomeException a) -> n (Either SomeException b)) -> CatchT m a -> CatchT n b Source #

Map the unwrapped computation using the given function.

    runCatchT (mapCatchT f m) = f (runCatchT m)

# Typeclass

The mtl style typeclass

module Control.Monad.Catch