{-# LANGUAGE Trustworthy #-}
module Grisette.Lib.Control.Monad.Except
(
mrgThrowError,
mrgCatchError,
)
where
import Control.Monad.Except
import Grisette.Core.Control.Monad.Union
import Grisette.Core.Data.Class.Bool
import Grisette.Core.Data.Class.Mergeable
import Grisette.Core.Data.Class.SimpleMergeable
mrgThrowError :: (MonadError e m, MonadUnion m, Mergeable a) => e -> m a
mrgThrowError :: forall e (m :: * -> *) a.
(MonadError e m, MonadUnion m, Mergeable a) =>
e -> m a
mrgThrowError = m a -> m a
forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge (m a -> m a) -> (e -> m a) -> e -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError
{-# INLINE mrgThrowError #-}
mrgCatchError ::
(MonadError e m, MonadUnion m, Mergeable a) =>
m a ->
(e -> m a) ->
m a
mrgCatchError :: forall e (m :: * -> *) a.
(MonadError e m, MonadUnion m, Mergeable a) =>
m a -> (e -> m a) -> m a
mrgCatchError m a
v e -> m a
handler = m a -> m a
forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge (m a -> m a) -> m a -> m a
forall a b. (a -> b) -> a -> b
$ m a
v m a -> (e -> m a) -> m a
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` (m a -> m a
forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge (m a -> m a) -> (e -> m a) -> e -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
handler)
{-# INLINE mrgCatchError #-}