From 848100338eec665215f44dbde9687ae69dd34d2a Mon Sep 17 00:00:00 2001 From: chak Date: Tue, 24 May 2005 04:45:15 +0000 Subject: [PATCH] [project @ 2005-05-24 04:45:15 by chak] More details about the representation of types after type checking. --- ghc/docs/comm/the-beast/types.html | 73 +++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/ghc/docs/comm/the-beast/types.html b/ghc/docs/comm/the-beast/types.html index 359cbf5..762a4c4 100644 --- a/ghc/docs/comm/the-beast/types.html +++ b/ghc/docs/comm/the-beast/types.html @@ -65,15 +65,44 @@ data TyNote type synonym together with a note stating its source form.

+

Creating Representation Types of Synonyms

+

+ 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. +

+

Newtypes

- 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 + PredTypes 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.

Predicates

@@ -97,7 +126,33 @@ data PredType Type.predTypeRep.

-

Classes and Instances

+

Representation of Type Constructors

+

+ 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. +

+ +

Representation of Classes and Instances

Class declarations turn into values of type Class.Class. They represent methods as the Ids 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

-- 1.7.10.4