Changes between Version 9 and Version 10 of Commentary/Compiler/HsSynType
- Timestamp:
- 10/04/06 14:06:37 (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Commentary/Compiler/HsSynType
v9 v10 18 18 There is significant mutual recursion between modules, and hence a couple of {{{lhs-boot}}} files. Look at [wiki:ModuleDependencies] to see the dependencies. 19 19 20 == Decorating `HsSyn` with type information == 21 20 22 The type checker adds type information to the syntax tree, otherwise leaving it as undisturbed as possible. This is done in two ways: 21 23 * Some constructors have a field of type {{{PostTcType}}}, which is just a synonym for {{{Type}}}. For example: … … 29 31 }}} 30 32 An {{{ExplicitList}}} represents the explicit list construct in Haskell (e.g. "{{{[2, 4, 1]}}}"). The parser fills the {{{PostTcType}}} field with an error thunk {{{HsTypes.placeHolderType}}}; and the renamer does not touch it. The typechecker figures out the type, and fills in the value. So until the type checker, we cannot examine or print the {{{PostTcType}}} fields. 33 34 The error thunks mean that we can't conveniently pretty-print the `PostTcType` fields, because the pretty-printer would poke the error thunks when run on pre-typchecked code. We could have defined `PostTcType` to be `Maybe Type`, but that would have meant unwrapping lots of `Just` constructors, which is messy. It would be nicer to parameterise `HsSyn` over the `PostTcType` fields. Thus: 35 {{{ 36 type RnHsBinds = HsBinds Name () -- After renaming 37 type TcHsBines = HsBinds Id Type -- After type checking 38 }}} 39 This would be a Good Thing to do. 31 40 32 41 * In a few cases, the typechecker moves from one constructor to another. Example: … … 48 57 49 58 * There are a few constructors added by type checker (rather than replacing an input constructor), particularly: 50 * {{{Hs Coerce}}}, in the {{{HsExpr}}} type.59 * {{{HsWrap}}}, in the {{{HsExpr}}} type. 51 60 * {{{AbsBinds}}}, in the {{{HsBinds}}} type. 52 SLPJ:These are invariably to do with type abstraction and application, since Haskell source is implicitly generalized and instantiated, whereas GHC's intermediate form is explicitly generalized and instantiated.61 These are invariably to do with type abstraction and application, since Haskell source is implicitly generalized and instantiated, whereas GHC's intermediate form is explicitly generalized and instantiated. 53 62 54 Naming convention within the code: LHs means located Haskell, i.e., data wrapped with the Located constructor. 63 == Source Locations == 55 64 65 `HsSyn` makes heavy use of the `Located` type ([[GhcFile(compiler/BasicTypes/SrcLoc)]]): 66 {{{ 67 data Located e = L SrcSpan e 68 }}} 69 A `Located t` is just a pair of a `SrcSpan` (which describes the source location of `t`) and a syntax tree `t`. The module `SrcLoc` defines two other types: 70 * `SrcLoc` specifies a particular source location: (filename, line number, character position) 71 * `SrcSpan` specifes a range of source locations: (filename, start line number and character position, end line number and character position) 72 More details in [[GhcFile(compiler/BasicTypes/SrcLoc)]]. 73 74 Naming convention within the code: "`LHs`" means located Haskell, e.g. 75 {{{ 76 type LHsBinds n = Located (HsBinds n) 77 }}} 78
