-
-\end{code}
-
-%************************************************************************
-%* *
-\subsection{Type Classifications}
-%* *
-%************************************************************************
-
-A type is
-
- *unboxed* iff its representation is other than a pointer
- Unboxed types cannot instantiate a type variable
- Unboxed types are always unlifted.
-
- *lifted* A type is lifted iff it has bottom as an element.
- Closures always have lifted types: i.e. any
- let-bound identifier in Core must have a lifted
- type. Operationally, a lifted object is one that
- can be entered.
- (NOTE: previously "pointed").
-
- *algebraic* A type with one or more constructors. An algebraic
- type is one that can be deconstructed with a case
- expression. *NOT* the same as lifted types,
- because we also include unboxed tuples in this
- classification.
-
- *primitive* iff it is a built-in type that can't be expressed
- in Haskell.
-
-Currently, all primitive types are unlifted, but that's not necessarily
-the case. (E.g. Int could be primitive.)
-
-Some primitive types are unboxed, such as Int#, whereas some are boxed
-but unlifted (such as ByteArray#). The only primitive types that we
-classify as algebraic are the unboxed tuples.
-
-examples of type classifications:
-
-Type primitive boxed lifted algebraic
------------------------------------------------------------------------------
-Int#, Yes No No No
-ByteArray# Yes Yes No No
-(# a, b #) Yes No No Yes
-( a, b ) No Yes Yes Yes
-[a] No Yes Yes Yes
-
-%************************************************************************
-%* *
-\subsection{The data type}
-%* *
-%************************************************************************
-
-
-\begin{code}
-type Type = GenType Unused -- Used after typechecker
-
-type GenKind flexi = GenType flexi
-type Kind = Type
-
-type TyVarSubst = TyVarEnv Type
-type GenTyVarSubst flexi = TyVarEnv (GenType flexi)
-
-data GenType flexi -- Parameterised over the "flexi" part of a type variable
- = TyVarTy (GenTyVar flexi)
-
- | AppTy
- (GenType flexi) -- Function is *not* a TyConApp
- (GenType flexi)
-
- | TyConApp -- Application of a TyCon
- TyCon -- *Invariant* saturated appliations of FunTyCon and
- -- synonyms have their own constructors, below.
- [GenType flexi] -- Might not be saturated.
-
- | FunTy -- Special case of TyConApp: TyConApp FunTyCon [t1,t2]
- (GenType flexi)
- (GenType flexi)
-
- | NoteTy -- Saturated application of a type synonym
- (TyNote flexi)
- (GenType flexi) -- The expanded version
-
- | ForAllTy
- (GenTyVar flexi)
- (GenType flexi) -- TypeKind
-
-data TyNote flexi
- = SynNote (GenType flexi) -- The unexpanded version of the type synonym; always a TyConApp
- | FTVNote (GenTyVarSet flexi) -- The free type variables of the noted expression
-\end{code}
-
-
-%************************************************************************
-%* *
-\subsection{Wired-in type constructors
-%* *
-%************************************************************************
-
-We define a few wired-in type constructors here to avoid module knots
-
-\begin{code}
-funTyConName = mkWiredInTyConName funTyConKey pREL_GHC SLIT("->") funTyCon
-funTyCon = mkFunTyCon funTyConName (mkArrowKinds [boxedTypeKind, boxedTypeKind] boxedTypeKind)
-\end{code}
-
-\begin{code}
-mk_kind_name key str = mkGlobalName key pREL_GHC (varOcc str)
- (LocalDef mkBuiltinSrcLoc NotExported)
- -- mk_kind_name is a bit of a hack
- -- The LocalDef means that we print the name without
- -- a qualifier, which is what we want for these kinds.
-
-boxedKindConName = mk_kind_name boxedKindConKey SLIT("*")
-boxedKindCon = mkKindCon boxedKindConName superKind Boxed
-
-unboxedKindConName = mk_kind_name unboxedKindConKey SLIT("*#")
-unboxedKindCon = mkKindCon unboxedKindConName superKind Unboxed
-
-openKindConName = mk_kind_name openKindConKey SLIT("*?")
-openKindCon = mkKindCon openKindConName superKind Open
-\end{code}
-
-
-%************************************************************************
-%* *
-\subsection{Kinds}
-%* *
-%************************************************************************
-
-\begin{code}
-superKind :: GenKind flexi -- Box, the type of all kinds
-superKind = TyConApp superKindCon []
-
-boxedTypeKind, unboxedTypeKind, openTypeKind :: GenKind flexi
-boxedTypeKind = TyConApp boxedKindCon []
-unboxedTypeKind = TyConApp unboxedKindCon []
-openTypeKind = TyConApp openKindCon []
-
-mkArrowKind :: GenKind flexi -> GenKind flexi -> GenKind flexi
-mkArrowKind = FunTy
-
-mkArrowKinds :: [GenKind flexi] -> GenKind flexi -> GenKind flexi
-mkArrowKinds arg_kinds result_kind = foldr FunTy result_kind arg_kinds
-\end{code}
-
-\begin{code}
-hasMoreBoxityInfo :: GenKind flexi -> GenKind flexi -> Bool
-
-(NoteTy _ k1) `hasMoreBoxityInfo` k2 = k1 `hasMoreBoxityInfo` k2
-k1 `hasMoreBoxityInfo` (NoteTy _ k2) = k1 `hasMoreBoxityInfo` k2
-
-(TyConApp kc1 ts1) `hasMoreBoxityInfo` (TyConApp kc2 ts2)
- = ASSERT( null ts1 && null ts2 )
- kc2 `matchesTyCon` kc1 -- NB the reversal of arguments
-
-kind1@(FunTy _ _) `hasMoreBoxityInfo` kind2@(FunTy _ _)
- = ASSERT( kind1 == kind2 )
- True
- -- The two kinds can be arrow kinds; for example when unifying
- -- (m1 Int) and (m2 Int) we end up unifying m1 and m2, which should
- -- have the same kind.
-
--- Other cases are impossible