module DDC.Type.Predicates
(
isBNone
, isBAnon
, isBName
, isTVar
, isBot
, isAtomT
, isDataKind
, isRegionKind
, isEffectKind
, isClosureKind
, isWitnessKind
, isAlgDataType
, isWitnessType
, isConstWitType
, isMutableWitType
, isDistinctWitType
, isReadEffect
, isWriteEffect
, isAllocEffect
, isSomeReadEffect
, isSomeWriteEffect
, isSomeAllocEffect)
where
import DDC.Type.Exp
import DDC.Type.Compounds
import qualified DDC.Type.Sum as T
isBNone :: Bind n -> Bool
isBNone bb
= case bb of
BNone{} -> True
_ -> False
isBAnon :: Bind n -> Bool
isBAnon bb
= case bb of
BAnon{} -> True
_ -> False
isBName :: Bind n -> Bool
isBName bb
= case bb of
BName{} -> True
_ -> False
isTVar :: Type n -> Bool
isTVar tt
= case tt of
TVar{} -> True
_ -> False
isBot :: Type n -> Bool
isBot tt
| TSum ss <- tt
, [] <- T.toList ss
= True
| otherwise = False
isAtomT :: Type n -> Bool
isAtomT tt
= case tt of
TVar{} -> True
TCon{} -> True
_ -> isBot tt
isDataKind :: Kind n -> Bool
isDataKind tt
= case tt of
TCon (TyConKind KiConData) -> True
_ -> False
isRegionKind :: Region n -> Bool
isRegionKind tt
= case tt of
TCon (TyConKind KiConRegion) -> True
_ -> False
isEffectKind :: Kind n -> Bool
isEffectKind tt
= case tt of
TCon (TyConKind KiConEffect) -> True
_ -> False
isClosureKind :: Kind n -> Bool
isClosureKind tt
= case tt of
TCon (TyConKind KiConClosure) -> True
_ -> False
isWitnessKind :: Kind n -> Bool
isWitnessKind tt
= case tt of
TCon (TyConKind KiConWitness) -> True
_ -> False
isAlgDataType :: Eq n => Type n -> Bool
isAlgDataType tt
| Just (tc, _) <- takeTyConApps tt
, TyConBound _ k <- tc
= takeResultKind k == kData
| otherwise
= False
isWitnessType :: Eq n => Type n -> Bool
isWitnessType tt
= case takeTyConApps tt of
Just (TyConWitness _, _) -> True
_ -> False
isConstWitType :: Eq n => Type n -> Bool
isConstWitType tt
= case takeTyConApps tt of
Just (TyConWitness TwConConst, _) -> True
_ -> False
isMutableWitType :: Eq n => Type n -> Bool
isMutableWitType tt
= case takeTyConApps tt of
Just (TyConWitness TwConMutable, _) -> True
_ -> False
isDistinctWitType :: Eq n => Type n -> Bool
isDistinctWitType tt
= case takeTyConApps tt of
Just (TyConWitness (TwConDistinct _), _) -> True
_ -> False
isReadEffect :: Effect n -> Bool
isReadEffect eff
= case eff of
TApp (TCon (TyConSpec TcConRead)) _ -> True
_ -> False
isWriteEffect :: Effect n -> Bool
isWriteEffect eff
= case eff of
TApp (TCon (TyConSpec TcConWrite)) _ -> True
_ -> False
isAllocEffect :: Effect n -> Bool
isAllocEffect eff
= case eff of
TApp (TCon (TyConSpec TcConAlloc)) _ -> True
_ -> False
isSomeReadEffect :: Effect n -> Bool
isSomeReadEffect tt
= case tt of
TApp (TCon (TyConSpec con)) _
-> case con of
TcConRead -> True
TcConHeadRead -> True
TcConDeepRead -> True
_ -> False
_ -> False
isSomeWriteEffect :: Effect n -> Bool
isSomeWriteEffect tt
= case tt of
TApp (TCon (TyConSpec con)) _
-> case con of
TcConWrite -> True
TcConDeepWrite -> True
_ -> False
_ -> False
isSomeAllocEffect :: Effect n -> Bool
isSomeAllocEffect tt
= case tt of
TApp (TCon (TyConSpec con)) _
-> case con of
TcConAlloc -> True
TcConDeepAlloc -> True
_ -> False
_ -> False