From 848100338eec665215f44dbde9687ae69dd34d2a Mon Sep 17 00:00:00 2001
From: chak
+ During translation from HsType
to Type
the
+ function Type.mkSynTy
is used to construct representations
+ of applications of type synonyms. It creates a NoteTy
node
+ if the synonym is applied to a sufficient number of arguments;
+ otherwise, it builds a simple TyConApp
and leaves it to
+ TcMType.checkValidType
to pick up invalid unsaturated
+ synonym applications. While creating a NoteTy
,
+ mkSynTy
also expands the synonym by substituting the type
+ arguments for the parameters of the synonym definition, using
+ Type.substTyWith
.
+
+ The function mkSynTy
is used indirectly via
+ mkGenTyConApp
, mkAppTy
, and
+ mkAppTy
, which construct type representations involving
+ type applications. The function mkSynTy
is also used
+ directly during type checking interface files; this is for tedious
+ reasons to do with forall hoisting - see the comment at
+ TcIface.mkIfTcApp
.
+
- Slightly more involved are data types declared via a
- newtype
declaration. These newtypes constitute new type
- constructors---i.e., they are not just type macros, but introduce new
- type names. However, provide that a newtype is not recursive, we still
- want to implement it by its representation type. In other words,
- tcEqType
cannot see through a newtype, but
- coreEqType
can.
+ Data types declared by a newtype
declarationx constitute new
+ type constructors---i.e., they are not just type macros, but introduce
+ new type names. However, provided that a newtype is not recursive, we
+ still want to implement it by its representation type. GHC realises this
+ by providing two flavours of type equality: (1) tcEqType
is
+ source-level type equality, which compares newtypes and
+ PredType
s by name, and (2) coreEqType
compares
+ them structurally (by using deepCoreView
to expand the
+ representation before comparing). The function
+ deepCoreView
(via coreView
) invokes
+ expandNewTcApp
for every type constructor application
+ (TyConApp
) to determine whether we are looking at a newtype
+ application that needs to be expanded to its representation type.
Type.predTypeRep
.
-
+ Type constructor applications are represented in Type
by
+ the variant TyConApp :: TyCon -> [Type] -> Type
. The first
+ argument to TyConApp
, namely TyCon.TyCon
,
+ distinguishes between function type constructors (variant
+ FunTyCon
) and algebraic type constructors (variant
+ AlgTyCon
), which arise from data and newtype declarations.
+ The variant AlgTyCon
contains all the information contained
+ from the data/newtype declaration as well as derived information, such
+ as the Unique
and argument variance information. This
+ includes a field algTcRhs :: AlgTyConRhs
, where
+ AlgTyConRhs
distinguishes three kinds of algebraic data
+ type declarations: (1) declarations that have been exported abstractly,
+ (2) data
declarations, and (3) newtype
+ declarations. The last of these both include their original right hand
+ side as well as the "ultimate" representation type, which is the right
+ hand side after expanding all type synonyms and non-recursive newtypes.
+
+ Both data and newtype declarations refer to their data constructors
+ represented as DataCon.DataCon
, which include all details
+ of their signature (as derived from the original declaration) as well
+ information for code generation, such as their tag value.
+
Class declarations turn into values of type Class.Class
.
They represent methods as the Id
s of the dictionary
@@ -115,7 +170,7 @@ data PredType
-Last modified: Thu May 12 22:47:50 EST 2005 +Last modified: Tue May 24 14:44:18 EST 2005