module Data.Has.Engine where
infixr 5 :*:
data a :*: b = a :*: b
deriving (Eq,Ord,Show,Read,Bounded)
data TyTrue = TyTrue
data TyFalse = TyFalse
instance Show TyTrue where show _ = "TyTrue"
instance Show TyFalse where show _ = "TyFalse"
class MayHave e s where
inj' :: e -> s -> Maybe s
prj' :: s -> Maybe e
class Contains e s bool | e s -> bool where
contains :: e -> s -> bool
class TyOr a b r | a b -> r where
tyor :: a -> b -> r
instance MayHave e f where
inj' _ _ = Nothing
prj' _ = Nothing
instance MayHave e e where
inj' e _ = Just e
prj' e = Just e
instance (MayHave e h,MayHave e t) => MayHave e (h :*: t) where
inj' e ~(h:*:t) = maybe (fmap (h:*:) (inj' e t)) (Just . (:*:t)) (inj' e h)
prj' ~(h:*:t) = maybe (prj' t) Just (prj' h)
instance (b ~ TyTrue) => Contains e e b where
contains _ _ = TyTrue
instance (b ~ TyFalse) => Contains e f b where
contains _ _ = TyFalse
instance (TyOr x y b, Contains e h x, Contains e t y) => Contains e (h :*: t) b where
contains e ~(h:*:t) = contains e h `tyor` contains e t
instance TyOr TyTrue b TyTrue where
tyor _ _ = TyTrue
instance TyOr TyFalse b b where
tyor _ b = b