| 40 | == Terminology == |
| 41 | |
| 42 | '''Parametric type constructors''': Type constructors in vanilla Haskell. |
| 43 | |
| 44 | '''Indexed type constructors''': Type constructors that are defined via one or more type declarations that have non-variable parameters. We often call them sloppily just ''indexed types''. |
| 45 | |
| 46 | '''Kind signature''': Declaration of the name, kind, and arity of an indexed type constructor. The ''arity'' is the number of type indexes - ''not'' the overall number of parameters - of an indexed type constructor. |
| 47 | |
| 48 | '''Type function''': An indexed type synonym. |
| 49 | |
| 50 | '''Indexed data type''': An indexed type constructor declared with `data` or `newtype`. |
| 51 | |
| 52 | '''Associated type''': An indexed type that is declared in a type class. |
| 53 | |
| 54 | '''Definitions vs. declarations''': We sometimes call the kind signature of an indexed constructor its ''declaration'' and the subsequent population of the type family by type equations or indexed data/newtype declarations the constructor's ''definition''. |
| 55 | |
56 | | * If it is `Just pats`, we have the definition of an associated data type or a type function equations (toplevel or nested in an instance declarations). Then, 'pats' are type patterns for the type-indexes of the type constructor and `tcdVars` are the variables in those patterns. Hence, the arity of the type constructor is `length tcdPats` and ''not'' `length tcdVars`. |
57 | | In both cases (and as before type functions), `tcdVars` collects all variables we need to quantify over. |
| 76 | * If it is `Just pats`, we have the definition of an a indexed type (toplevel or nested in an instance declarations). Then, 'pats' are type patterns for the type-indexes of the type constructor and `tcdVars` are the variables in those patterns. Hence, the arity of the type constructor is `length tcdPats` and ''not'' `length tcdVars`. |
| 77 | In both cases (and as before we had type functions), `tcdVars` collects all variables we need to quantify over. |
61 | | The LALR parser allows arbitrary types as left-hand sides in '''data''' and '''type''' declarations. The parsed type is, then, passed to {{{RdHsSyn.checkTyClHdr}}} for closer analysis (possibly via `RdHsSyn.checkSynHdr`). It decomposes the type and, among other things, yields the type arguments in their original form plus all type variables they contain. Subsequently, {{{RdrHsSyn.checkTyVars}}} is used to either enforce that all type arguments are variables (second argument is `False`) or to simply check whether the type arguments are variables (second argument `True`). If in enforcing mode, `checkTyVars` will raise an error if it encounters a non-variable (e.g., required for class declarations). If in checking mode, it yields the value placed in the `tcdPats` field described above; i.e., returns `Nothing` instead of the type arguments if these arguments are all only variables. |
62 | | |
63 | | NB: Some well-formedness checks are left for the renamer to do. For example, we don't enforce at this point that toplevel data declarations use variable-only heads (as this requires context information not available during parsing). |
| 81 | The LALR parser allows arbitrary types as left-hand sides in '''data''', '''newtype''', and '''type''' declarations. The parsed type is, then, passed to {{{RdHsSyn.checkTyClHdr}}} for closer analysis (possibly via `RdHsSyn.checkSynHdr`). It decomposes the type and, among other things, yields the type arguments in their original form plus all type variables they contain. Subsequently, {{{RdrHsSyn.checkTyVars}}} is used to either enforce that all type arguments are variables (second argument is `False`) or to simply check whether the type arguments are variables (second argument `True`). If in enforcing mode, `checkTyVars` will raise an error if it encounters a non-variable (e.g., required for class declarations). If in checking mode, it yields the value placed in the `tcdPats` field described above; i.e., returns `Nothing` instead of the type arguments if these arguments are all only variables. |