MonadCatch and MonadThrow instances for Test

This commit is contained in:
Arya Irani 2021-04-07 14:14:49 -06:00
parent 844deaa9c1
commit 8d05785c30
2 changed files with 10 additions and 0 deletions

View File

@ -58,6 +58,7 @@ library
build-depends:
async >= 2.1.1,
base >= 4.3,
exceptions,
mtl >= 2.0.1,
containers >= 0.4.0,
stm >= 2.4,

View File

@ -9,6 +9,8 @@ import Control.Concurrent
import Control.Concurrent.STM
import Control.Exception
import Control.Monad
import Control.Monad.Catch (MonadCatch, MonadThrow(throwM))
import qualified Control.Monad.Catch as Catch
import Control.Monad.IO.Class
import Control.Monad.Reader
import Data.List
@ -404,6 +406,13 @@ instance Monad Test where
instance MonadFail Test where
fail = crash
instance MonadThrow Test where
throwM = Test . throwM
instance MonadCatch Test where
catch (Test m) f =
Test $ Catch.catch m (\e -> case f e of Test m' -> m')
instance Functor Test where
fmap = liftM