Elm Exactly

Rule 20s-valbind-var

Value BindingsC⊢valbind⇒VE\jdg{C}{\valbind}{\VE}
⟨U′ is new for ty in CC+U′⊢ty⇒τU′∩tyvars C=∅⟩C⟨+U′⟩⊢exp⇒τ⟨ ⁣⟨C⊢valbind⇒VE⟩ ⁣⟩C⊢var ⟨: ty⟩ = exp ⟨ ⁣⟨and valbind⟩ ⁣⟩⇒{var↦(⟨∀U′.⟩τ,v)} ⟨ ⁣⟨+VE⟩ ⁣⟩\frac{\begin{array}{c}\opt{U' \text{ is new for } \ty \text{ in } C \premsep \jdg{C + U'}{\ty}{\tau} \premsep U' \cap \tyvars C = \emptyset} \\ \jdg{C\opt{{}+U'}}{\expm}{\tau} \premsep \optt{\jdg{C}{\valbind}{\VE}}\end{array}}{\begin{array}{c}\jdg{C}{\var\ \opt{\kw{:}\ \ty}\ \kw{=}\ \expm\ \optt{\kw{and}\ \valbind}}{\{\var \mapsto (\opt{\forall U'.}\tau, \isv)\}\ \optt{{}+\VE}}\end{array}}
(20)
Read it in its chapter·Permanent address: /standard/rules/s-valbind-var

Comments

When the second option is present, var∉Dom VE\var \notin \Dom\VE by the syntactic restrictions. With an annotation, U′U' holds the variables of ty\ty not already explicit in CC (Section 4.7). They are in UU while ty\ty and exp\expm elaborate, so an annotation nested in exp\expm that writes one of their names means the same variable. Since τ\tau is fixed by ty\ty, exp\expm must have exactly that type, with the variables of U′U' uninstantiated: an annotation may be less general than the type exp\expm could have, but never more general. Thus f : a -> a with f x = x + 1 does not elaborate, nor does g : number -> number with g x = x // 2.

The condition U′∩tyvars C=∅U' \cap \tyvars C = \emptyset prevents an explicit variable from escaping its annotation. In f x = let g : a -> a ; g y = x in g x, the body of g has type a -> a only if x has the explicit type a, which is then free in the context of g; so the expression does not elaborate.

Referred to from

TeX source
\defnrule[r:s-valbind-var]
  {\opt{U' \text{ is new for } \ty \text{ in } C \premsep \jdg{C + U'}{\ty}{\tau} \premsep U' \cap \tyvars C = \emptyset} \\ \jdg{C\opt{{}+U'}}{\expm}{\tau} \premsep \optt{\jdg{C}{\valbind}{\VE}}}
  {\jdg{C}{\var\ \opt{\kw{:}\ \ty}\ \kw{=}\ \expm\ \optt{\kw{and}\ \valbind}}{\{\var \mapsto (\opt{\forall U'.}\tau, \isv)\}\ \optt{{}+\VE}}}

Tests (101)

Discussions

Discuss this rule·Search the discussions on GitHub

Discussions are on GitHub; one about this rule has [r:s-valbind-var] 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.