module Kind (
Kind,
isLiftedTypeKind, isUnliftedTypeKind,
isConstraintKind,
isTYPEApp,
returnsTyCon, returnsConstraintKind,
isConstraintKindCon,
classifiesTypeWithValues,
isStarKind, isStarKindSynonymTyCon,
tcIsStarKind,
isKindLevPoly
) where
#include "HsVersions.h"
import GhcPrelude
import Type ( coreView, tcView
, splitTyConApp_maybe )
import DataCon ( DataCon )
import TyCoRep
import TyCon
import PrelNames
import Outputable
import Util
isConstraintKind :: Kind -> Bool
isConstraintKindCon :: TyCon -> Bool
isConstraintKindCon tc = tyConUnique tc == constraintKindTyConKey
isConstraintKind (TyConApp tc _) = isConstraintKindCon tc
isConstraintKind _ = False
isTYPEApp :: Kind -> Maybe DataCon
isTYPEApp (TyConApp tc args)
| tc `hasKey` tYPETyConKey
, [arg] <- args
, Just (tc, []) <- splitTyConApp_maybe arg
, Just dc <- isPromotedDataCon_maybe tc
= Just dc
isTYPEApp _ = Nothing
returnsTyCon :: Unique -> Type -> Bool
returnsTyCon tc_u (ForAllTy _ ty) = returnsTyCon tc_u ty
returnsTyCon tc_u (FunTy _ ty) = returnsTyCon tc_u ty
returnsTyCon tc_u (TyConApp tc' _) = tc' `hasKey` tc_u
returnsTyCon _ _ = False
returnsConstraintKind :: Kind -> Bool
returnsConstraintKind = returnsTyCon constraintKindTyConKey
isKindLevPoly :: Kind -> Bool
isKindLevPoly k = ASSERT2( isStarKind k || _is_type, ppr k )
go k
where
go ty | Just ty' <- coreView ty = go ty'
go TyVarTy{} = True
go AppTy{} = True
go (TyConApp tc tys) = isFamilyTyCon tc || any go tys
go ForAllTy{} = True
go (FunTy t1 t2) = go t1 || go t2
go LitTy{} = False
go CastTy{} = True
go CoercionTy{} = True
_is_type
| TyConApp typ [_] <- k
= typ `hasKey` tYPETyConKey
| otherwise
= False
classifiesTypeWithValues :: Kind -> Bool
classifiesTypeWithValues t | Just t' <- coreView t = classifiesTypeWithValues t'
classifiesTypeWithValues (TyConApp tc [_]) = tc `hasKey` tYPETyConKey
classifiesTypeWithValues _ = False
tcIsStarKind :: Kind -> Bool
tcIsStarKind k | Just k' <- tcView k = isStarKind k'
tcIsStarKind (TyConApp tc [TyConApp ptr_rep []])
= tc `hasKey` tYPETyConKey
&& ptr_rep `hasKey` liftedRepDataConKey
tcIsStarKind _ = False
isStarKind :: Kind -> Bool
isStarKind k | Just k' <- coreView k = isStarKind k'
isStarKind (TyConApp tc [TyConApp ptr_rep []])
= tc `hasKey` tYPETyConKey
&& ptr_rep `hasKey` liftedRepDataConKey
isStarKind _ = False
isStarKindSynonymTyCon :: TyCon -> Bool
isStarKindSynonymTyCon tc = tc `hasKey` constraintKindTyConKey