Changes between Version 9 and Version 10 of Commentary/Compiler/HsSynType


Ignore:
Timestamp:
Oct 4, 2006 9:06:37 PM (9 years ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/HsSynType

    v9 v10  
    1818There is significant mutual recursion between modules, and hence a couple of {{{lhs-boot}}} files. Look at [wiki:ModuleDependencies] to see the dependencies.
    1919
     20== Decorating `HsSyn` with type information ==
     21
    2022The type checker adds type information to the syntax tree, otherwise leaving it as undisturbed as possible.  This is done in two ways:
    2123  * Some constructors have a field of type {{{PostTcType}}}, which is just a synonym for {{{Type}}}. For example:
     
    2931}}}
    3032  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.
    3140
    3241  * In a few cases, the typechecker moves from one constructor to another.  Example:
     
    4857
    4958  * There are a few constructors added by type checker (rather than replacing an input constructor), particularly:
    50     * {{{HsCoerce}}}, in the {{{HsExpr}}} type.
     59    * {{{HsWrap}}}, in the {{{HsExpr}}} type.
    5160    * {{{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.
    5362
    54 Naming convention within the code: LHs means located Haskell, i.e., data wrapped with the Located constructor.
     63== Source Locations ==
    5564
     65`HsSyn` makes heavy use of the `Located` type ([[GhcFile(compiler/BasicTypes/SrcLoc)]]):
     66{{{
     67data Located e = L SrcSpan e
     68}}}
     69A `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)
     72More details in [[GhcFile(compiler/BasicTypes/SrcLoc)]].
     73
     74Naming convention within the code: "`LHs`" means located Haskell, e.g.
     75{{{
     76type LHsBinds n = Located (HsBinds n)
     77}}}
     78