Commit c676a15e authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Define TypeVar (like KindVar), isTypeVar, isKindVar, and use them

This is the start of more global renaming
parent fcf977a5
......@@ -39,7 +39,8 @@
module Var (
-- * The main data type and synonyms
Var, TyVar, CoVar, Id, KindVar, DictId, DFunId, EvVar, EqVar, EvId, IpId,
Var, CoVar, Id, DictId, DFunId, EvVar, EqVar, EvId, IpId,
TyVar, TypeVar, KindVar, TKVar,
-- ** Taking 'Var's apart
varName, varUnique, varType,
......@@ -54,7 +55,7 @@ module Var (
setIdExported, setIdNotExported,
-- ** Predicates
isId, isTyVar, isTcTyVar,
isId, isTKVar, isTyVar, isTcTyVar,
isLocalVar, isLocalId,
isGlobalId, isExportedId,
mustHaveLocalBinding,
......@@ -102,7 +103,10 @@ import Data.Data
\begin{code}
type Id = Var -- A term-level identifier
type TyVar = Var -- Type *or* kind variable
type TyVar = Var -- Type *or* kind variable (historical)
type TKVar = Var -- Type *or* kind variable (historical)
type TypeVar = Var -- Definitely a type variable
type KindVar = Var -- Definitely a kind variable
-- See Note [Kind and type variables]
......@@ -136,8 +140,8 @@ Before kind polymorphism, TyVar were used to mean type variables. Now
they are use to mean kind *or* type variables. KindVar is used when we
know for sure that it is a kind variable. In future, we might want to
go over the whole compiler code to use:
- KiTyVar to mean kind or type variables
- TyVar to mean type variables only
- TKVar to mean kind or type variables
- TypeVar to mean type variables only
- KindVar to mean kind variables
......@@ -157,13 +161,13 @@ in its @VarDetails@.
-- | Essentially a typed 'Name', that may also contain some additional information
-- about the 'Var' and it's use sites.
data Var
= TyVar { -- type and kind variables
= TyVar { -- Type and kind variables
-- see Note [Kind and type variables]
varName :: !Name,
realUnique :: FastInt, -- Key for fast comparison
-- Identical to the Unique in the name,
-- cached here for speed
varType :: Kind -- ^ The type or kind of the 'Var' in question
realUnique :: FastInt, -- Key for fast comparison
-- Identical to the Unique in the name,
-- cached here for speed
varType :: Kind -- ^ The type or kind of the 'Var' in question
}
| TcTyVar { -- Used only during type inference
......@@ -411,10 +415,13 @@ setIdNotExported id = ASSERT( isLocalId id )
%************************************************************************
\begin{code}
isTyVar :: Var -> Bool -- True of both type variables only
isTyVar (TyVar {}) = True
isTyVar (TcTyVar {}) = True
isTyVar _ = False
isTyVar :: Var -> Bool
isTyVar = isTKVar -- Historical
isTKVar :: Var -> Bool -- True of both type and kind variables
isTKVar (TyVar {}) = True
isTKVar (TcTyVar {}) = True
isTKVar _ = False
isTcTyVar :: Var -> Bool
isTcTyVar (TcTyVar {}) = True
......
......@@ -23,7 +23,7 @@ module TypeRep (
-- Functions over types
mkTyConApp, mkTyConTy, mkTyVarTy, mkTyVarTys,
isLiftedTypeKind,
isLiftedTypeKind, isSuperKind, isTypeVar, isKindVar,
-- Pretty-printing
pprType, pprParendType, pprTypeApp,
......@@ -257,11 +257,25 @@ mkTyConApp tycon tys
-- | Create the plain type constructor type which has been applied to no type arguments at all.
mkTyConTy :: TyCon -> Type
mkTyConTy tycon = mkTyConApp tycon []
\end{code}
Some basic functions, put here to break loops eg with the pretty printer
\begin{code}
isLiftedTypeKind :: Kind -> Bool
-- This function is here because it's used in the pretty printer
isLiftedTypeKind (TyConApp tc []) = tc `hasKey` liftedTypeKindTyConKey
isLiftedTypeKind _ = False
-- | Is this a super-kind (i.e. a type-of-kinds)?
isSuperKind :: Type -> Bool
isSuperKind (TyConApp skc []) = skc `hasKey` superKindTyConKey
isSuperKind _ = False
isTypeVar :: Var -> Bool
isTypeVar v = isTKVar v && not (isSuperKind (varType v))
isKindVar :: Var -> Bool
isKindVar v = isTKVar v && isSuperKind (varType v)
\end{code}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment