Control.Monad.Catch.Pure
| Copyright | (C) Edward Kmett 2013-2015 (c) Google Inc. 2012 |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Edward Kmett <[email protected]> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | Trustworthy |
| Language | Haskell98 |
Contents
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!
Transformer
The transformers-style monad transfomer
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
| |
Instances
| MonadTrans CatchT | |
Defined in Control.Monad.Catch.Pure | |
| MonadRWS r w s m => MonadRWS r w s (CatchT m) | |
Defined in Control.Monad.Catch.Pure | |
| MonadWriter w m => MonadWriter w (CatchT m) | |
| MonadState s m => MonadState s (CatchT m) | |
| MonadReader e m => MonadReader e (CatchT m) | |
| Monad m => Monad (CatchT m) | |
| Monad m => Functor (CatchT m) | |
| MonadFix m => MonadFix (CatchT m) | |
Defined in Control.Monad.Catch.Pure | |
| Monad m => MonadFail (CatchT m) | |
Defined in Control.Monad.Catch.Pure | |
| Monad m => Applicative (CatchT m) | |
Defined in Control.Monad.Catch.Pure | |
| Foldable m => Foldable (CatchT m) | |
Defined in Control.Monad.Catch.Pure Methodsfold :: 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 | |
| (Monad m, Traversable m) => Traversable (CatchT m) | |
Defined in Control.Monad.Catch.Pure | |
| MonadIO m => MonadIO (CatchT m) | |
Defined in Control.Monad.Catch.Pure | |
| Monad m => Alternative (CatchT m) | |
| Monad m => MonadPlus (CatchT m) | |
| Monad m => MonadMask (CatchT m) |
Note: This instance is only valid if the underlying monad has a single exit point! For example, |
Defined in Control.Monad.Catch.Pure | |
| Monad m => MonadCatch (CatchT m) | |
| Monad m => MonadThrow (CatchT m) | |
Defined in Control.Monad.Catch.Pure | |
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
© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).
https://downloads.haskell.org/~ghc/8.10.2/docs/html/libraries/exceptions-0.10.4/Control-Monad-Catch-Pure.html