Commit 134aec9a authored by Michael Snoyman's avatar Michael Snoyman
Browse files

Add instances for MonadCatch and MonadMask for Either

Came up in a discussion with @bitonic. There's no downside I can see to
the MonadCatch instance. However, the MonadMask instance is a little bit
more controversial, in that it's not actually doing any masking.
However, it's impossible to know that it's not masking the async
exceptions since there are no side-effects from the Either monad.

Of course, by using unsafePerformIO, we could observe the difference,
but I think that's a valid trade-off.

One final argument against MonadMask for Either: it's probably not
terribly useful.
parent 02bfff54
* `MonadCatch` and `MonadMask` instances for `Either SomeException`
* Support for throwing in the `template-haskell` `Q` monad
name: exceptions
category: Control, Exceptions, Monad
version: 0.8.3
cabal-version: >= 1.8
license: BSD3
license-file: LICENSE
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment