module Test.StateMachine.Types.References
( Reference(..)
, concrete
, opaque
, Opaque(..)
, Symbolic(..)
, Concrete(..)
, Var(..)
) where
import Data.Functor.Classes
(Eq1(..), Ord1(..), Show1(..), compare1, eq1,
showsPrec1)
import Data.Typeable
(Typeable)
import Test.StateMachine.Types.HFunctor
newtype Reference v a = Reference (v a)
concrete :: Reference Concrete a -> a
concrete (Reference (Concrete x)) = x
opaque :: Reference Concrete (Opaque a) -> a
opaque (Reference (Concrete (Opaque x))) = x
instance (Eq1 v, Eq a) => Eq (Reference v a) where
(==) (Reference x) (Reference y) = eq1 x y
instance (Ord1 v, Ord a) => Ord (Reference v a) where
compare (Reference x) (Reference y) = compare1 x y
instance (Show1 v, Show a) => Show (Reference v a) where
showsPrec p (Reference v) = showParen (p > appPrec) $
showString "Reference " .
showsPrec1 p v
where
appPrec = 10
deriving instance Read (v a) => Read (Reference v a)
instance HTraversable Reference where
htraverse f (Reference v) = fmap Reference (f v)
instance HFunctor Reference
instance HFoldable Reference
newtype Opaque a = Opaque
{ unOpaque :: a
} deriving (Eq, Ord)
instance Show (Opaque a) where
showsPrec _ (Opaque _) = showString "Opaque"
newtype Var = Var Int
deriving (Eq, Ord, Show, Num, Read)
data Symbolic a where
Symbolic :: Typeable a => Var -> Symbolic a
deriving instance Eq (Symbolic a)
deriving instance Ord (Symbolic a)
deriving instance Show (Symbolic a)
deriving instance Typeable a => Read (Symbolic a)
deriving instance Foldable Symbolic
instance Eq1 Symbolic where
liftEq _ (Symbolic x) (Symbolic y) = x == y
instance Ord1 Symbolic where
liftCompare _ (Symbolic x) (Symbolic y) = compare x y
instance Show1 Symbolic where
liftShowsPrec _ _ p (Symbolic x) =
showParen (p > appPrec) $
showString "Symbolic " .
showsPrec (appPrec + 1) x
where
appPrec = 10
newtype Concrete a where
Concrete :: a -> Concrete a
deriving (Eq, Ord, Show, Read, Functor, Foldable, Traversable)
instance Eq1 Concrete where
liftEq eq (Concrete x) (Concrete y) = eq x y
instance Ord1 Concrete where
liftCompare comp (Concrete x) (Concrete y) = comp x y
instance Show1 Concrete where
liftShowsPrec sp _ p (Concrete x) =
showParen (p > appPrec) $
showString "Concrete " .
sp (appPrec + 1) x
where
appPrec = 10