{-# 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 = forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge forall a b. (a -> b) -> a -> b
$ m a
v forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` (forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
handler)
{-# INLINE mrgCatchError #-}