[commit: ghc] master: Define TypeVar (like KindVar), isTypeVar, isKindVar, and use them (c676a15)
Simon Peyton Jones
simonpj at microsoft.com
Fri Feb 17 15:03:43 CET 2012
Repository : ssh://darcs.haskell.org//srv/darcs/ghc
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/c676a15e9b0ead9d9322d036d9cf2f4df734bb01
>---------------------------------------------------------------
commit c676a15e9b0ead9d9322d036d9cf2f4df734bb01
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Fri Feb 17 13:55:03 2012 +0000
Define TypeVar (like KindVar), isTypeVar, isKindVar, and use them
This is the start of more global renaming
>---------------------------------------------------------------
compiler/basicTypes/Var.lhs | 35 +++++++++++++++++++++--------------
compiler/types/TypeRep.lhs | 18 ++++++++++++++++--
2 files changed, 37 insertions(+), 16 deletions(-)
diff --git a/compiler/basicTypes/Var.lhs b/compiler/basicTypes/Var.lhs
index 6b58305..af7cb35 100644
--- a/compiler/basicTypes/Var.lhs
+++ b/compiler/basicTypes/Var.lhs
@@ -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 at .
-- | 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
diff --git a/compiler/types/TypeRep.lhs b/compiler/types/TypeRep.lhs
index 3bc1b23..9c1a1d7 100644
--- a/compiler/types/TypeRep.lhs
+++ b/compiler/types/TypeRep.lhs
@@ -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}
More information about the Cvs-ghc
mailing list