diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 7f3989ea0c44805e151720fb939b6a301a684841..d314d42c41179ac173e48e94d58b808f7acfe2b4 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,3 +1,7 @@ +0.8.3 +----- +* `MonadCatch` and `MonadMask` instances for `Either SomeException` + 0.8.1 ----- * Support for throwing in the `template-haskell` `Q` monad diff --git a/exceptions.cabal b/exceptions.cabal index c7c51e5f975407adb24b9c7ed0ad3cf55ef1bb7f..9c34a9ddfd070af49288e037a91e38a37d039314 100644 --- a/exceptions.cabal +++ b/exceptions.cabal @@ -1,6 +1,6 @@ name: exceptions category: Control, Exceptions, Monad -version: 0.8.2.1 +version: 0.8.3 cabal-version: >= 1.8 license: BSD3 license-file: LICENSE diff --git a/src/Control/Monad/Catch.hs b/src/Control/Monad/Catch.hs index 4d014447ce816d911ae8b109c35a7c37316909d9..546876c743f3221b1307cb52ed389aa434a2fe31 100644 --- a/src/Control/Monad/Catch.hs +++ b/src/Control/Monad/Catch.hs @@ -183,8 +183,6 @@ instance MonadThrow [] where throwM _ = [] instance MonadThrow Maybe where throwM _ = Nothing -instance e ~ SomeException => MonadThrow (Either e) where - throwM = Left . toException instance MonadThrow Q where throwM = fail . show @@ -201,6 +199,20 @@ instance MonadThrow STM where instance MonadCatch STM where catch = STM.catchSTM +instance e ~ SomeException => MonadThrow (Either e) where + throwM = Left . toException +-- | @since 0.8.3 +instance e ~ SomeException => MonadCatch (Either e) where + catch (Left e) f = + case fromException e of + Nothing -> Left e + Just e' -> f e' + catch x@(Right _) _ = x +-- | @since 0.8.3 +instance e ~ SomeException => MonadMask (Either e) where + mask f = f id + uninterruptibleMask f = f id + instance MonadThrow m => MonadThrow (IdentityT m) where throwM e = lift $ throwM e instance MonadCatch m => MonadCatch (IdentityT m) where