{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Trustworthy #-}
module Grisette.Core.Data.Class.Error
(
TransformError (..),
symAssertTransformableError,
symThrowTransformableError,
)
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
import {-# SOURCE #-} Grisette.IR.SymPrim.Data.SymPrim
class TransformError from to where
transformError :: from -> to
instance {-# OVERLAPPABLE #-} TransformError a a where
transformError :: a -> a
transformError = a -> a
forall a. a -> a
id
{-# INLINE transformError #-}
instance {-# OVERLAPS #-} TransformError a () where
transformError :: a -> ()
transformError a
_ = ()
{-# INLINE transformError #-}
instance {-# OVERLAPPING #-} TransformError () () where
transformError :: () -> ()
transformError ()
_ = ()
{-# INLINE transformError #-}
symThrowTransformableError ::
( Mergeable to,
Mergeable a,
TransformError from to,
MonadError to erm,
MonadUnion erm
) =>
from ->
erm a
symThrowTransformableError :: forall to a from (erm :: * -> *).
(Mergeable to, Mergeable a, TransformError from to,
MonadError to erm, MonadUnion erm) =>
from -> erm a
symThrowTransformableError = erm a -> erm a
forall (u :: * -> *) a. (UnionLike u, Mergeable a) => u a -> u a
merge (erm a -> erm a) -> (from -> erm a) -> from -> erm a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. to -> erm a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (to -> erm a) -> (from -> to) -> from -> erm a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. from -> to
forall from to. TransformError from to => from -> to
transformError
{-# INLINE symThrowTransformableError #-}
symAssertTransformableError ::
( Mergeable to,
TransformError from to,
MonadError to erm,
MonadUnion erm
) =>
from ->
SymBool ->
erm ()
symAssertTransformableError :: forall to from (erm :: * -> *).
(Mergeable to, TransformError from to, MonadError to erm,
MonadUnion erm) =>
from -> SymBool -> erm ()
symAssertTransformableError from
err SymBool
cond = SymBool -> erm () -> erm () -> erm ()
forall (u :: * -> *) a.
(UnionLike u, Mergeable a) =>
SymBool -> u a -> u a -> u a
mrgIf SymBool
cond (() -> erm ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (from -> erm ()
forall to a from (erm :: * -> *).
(Mergeable to, Mergeable a, TransformError from to,
MonadError to erm, MonadUnion erm) =>
from -> erm a
symThrowTransformableError from
err)
{-# INLINE symAssertTransformableError #-}