module Test.QuickCheck.StateModel.Lockstep.Op (
Operation(..)
, InterpretOp(..)
, WrapRealized(..)
, intOpRealizedId
, intOpTransformer
) where
import Test.QuickCheck.StateModel (Realized)
import Data.Coerce
class Operation op where
opIdentity :: op a a
class Operation op => InterpretOp op f where
intOp :: op a b -> f a -> Maybe (f b)
newtype WrapRealized m a = WrapRealized {
forall (m :: * -> *) a. WrapRealized m a -> Realized m a
unwrapRealized :: Realized m a
}
intOpRealizedId ::
(Realized m a ~ a, Realized m b ~ b)
=> (op a b -> a -> Maybe b)
-> op a b -> WrapRealized m a -> Maybe (WrapRealized m b)
intOpRealizedId :: forall (m :: * -> *) a b (op :: * -> * -> *).
(Realized m a ~ a, Realized m b ~ b) =>
(op a b -> a -> Maybe b)
-> op a b -> WrapRealized m a -> Maybe (WrapRealized m b)
intOpRealizedId = coerce :: forall a b. Coercible a b => a -> b
coerce
intOpTransformer ::
forall t m a b op.
( Realized (t m) a ~ Realized m a
, Realized (t m) b ~ Realized m b
, InterpretOp op (WrapRealized m)
)
=> op a b
-> WrapRealized (t m) a
-> Maybe (WrapRealized (t m) b)
intOpTransformer :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b
(op :: * -> * -> *).
(Realized (t m) a ~ Realized m a, Realized (t m) b ~ Realized m b,
InterpretOp op (WrapRealized m)) =>
op a b -> WrapRealized (t m) a -> Maybe (WrapRealized (t m) b)
intOpTransformer op a b
op WrapRealized (t m) a
wr = WrapRealized m b -> WrapRealized (t m) b
coerceOut forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (op :: * -> * -> *) (f :: * -> *) a b.
InterpretOp op f =>
op a b -> f a -> Maybe (f b)
intOp op a b
op (WrapRealized (t m) a -> WrapRealized m a
coerceIn WrapRealized (t m) a
wr)
where
coerceIn :: WrapRealized (t m) a -> WrapRealized m a
coerceIn :: WrapRealized (t m) a -> WrapRealized m a
coerceIn = coerce :: forall a b. Coercible a b => a -> b
coerce
coerceOut :: WrapRealized m b -> WrapRealized (t m) b
coerceOut :: WrapRealized m b -> WrapRealized (t m) b
coerceOut = coerce :: forall a b. Coercible a b => a -> b
coerce