Rule 57sm-topdec-types
Comments
The phrase consists of the custom types of a module, as one group, followed by its aliases, as Appendix A arranges them (Section A.2); here , and when the option is absent, in which case the phrase begins with the first alias, and when it is . Since occurs on both sides, every type constructor of the phrase is in scope in all of it: a constructor may take an argument whose type is an alias declared in the phrase, and an alias may mention a custom type of the phrase or another alias. The equation has a solution determined by and the phrase up to the choice of new type names (Section 5.5), because the type function of a custom type is its type name alone, and no alias refers to itself through aliases. The side condition on makes the type names of the custom types new. The side condition keeps the equation from justifying itself: the closures of rules (61) and (64) are taken in , so without it an environment whose constructors keep a free variable, as K : a -> T a for type T a = K a, would be a solution too; with it, the constructors are closed and is determined as the property above says. Rule (60) does not split such a phrase (its side condition), so the type declarations of a module are elaborated together, and their order does not matter: a custom type may mention an alias that follows it. A local type spelt as an imported one is a different type, and the unqualified type constructor denotes the local one, in the declarations before it as well as after it: with type T = T String followed by type alias String = Int, the constructor T takes an Int.
Referred to from
- Section 5.5 Inference Rules
- The comment on rule
sm-topdec-seq(Chapter 5) - The comment on rule
sm-datbind(Chapter 5) - Section 5.6 Principal Derivations
TeX source
\defnrule[r:sm-topdec-types]
{\opt{\jdg{C \oplus \TE}{\datbind}{\VE', \TE'} \premsep \forall (t, \VE'') \in \Ran\TE',\ t \notin T \of C} \\ \jdg{C \oplus \TE}{\typbind_i}{\VE_i, \TE_i} \quad (1 \le i \le l) \\ \TE = \opt{\TE' +{}} \TE_1 + \cdots + \TE_l \premsep \VE = \opt{\VE' +{}} \VE_1 + \cdots + \VE_l \\ \tyvars \TE = \emptyset}
{C \vdash \opt{\kw{type}\ \datbind\ \kw{;}}\ \kw{type alias}\ \typbind_1\ \kw{;}\ \cdots \\ \qquad \kw{;}\ \kw{type alias}\ \typbind_l \Rightarrow (\emptymap, \TE, \VE),\ \emptymap}Tests (5)
- elm / MinimalTypeAliasTestA type alias of a type name.
- elm / RecursiveMutualTypeTestA pair of mutually recursive custom types, `Forest` and `RoseTree`, can be built and traversed.
- elm / RecursiveTypeInRecordTestChecks that a custom type can recurse through a record carried by one of its constructors.
- elm / StandardA98TypeBeforeAliasStringMismatchTestA custom type declared before a local alias spelt like an imported type uses the local alias.
- elm / StandardA98TypeBeforeAliasTestA custom type may mention a local alias declared after it, even one spelt like an imported type.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:sm-topdec-types] in its title.
A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.