Elm Exactly

Rule 57sm-topdec-types

Top-level DeclarationsC⊢topdec⇒E,PE\jdg{C}{\topdec}{E, \PE}
⟨C⊕TE⊢datbind⇒VE′,TE′∀(t,VE′′)∈Ran TE′, t∉TofC⟩C⊕TE⊢typbindi⇒VEi,TEi(1≤i≤l)TE=⟨TE′+⟩TE1+⋯+TElVE=⟨VE′+⟩VE1+⋯+VEltyvars TE=∅C⊢⟨type datbind ;⟩ type alias typbind1 ; ⋯; type alias typbindl⇒({},TE,VE), {}\frac{\begin{array}{c}\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\end{array}}{\begin{array}{c}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\end{array}}
(57)
Read it in its chapter·Permanent address: /standard/rules/sm-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 l≥0l \geq 0, and l≥1l \geq 1 when the option is absent, in which case the phrase begins with the first alias, and when l=0l = 0 it is type datbind\kw{type}\ \datbind. Since TE\TE 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 CC 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 TofCT \of C makes the type names of the custom types new. The side condition tyvars TE=∅\tyvars\TE = \emptyset keeps the equation from justifying itself: the closures of rules (61) and (64) are taken in C⊕TEC \oplus \TE, 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 TE\TE 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

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)

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.