Elm Exactly

Rule 61sm-datbind

Custom-type BindingsC⊢datbind⇒VE,TE\jdg{C}{\datbind}{\VE, \TE}
tyvarseq=ξ(k)U={ξ1,⋯ ,ξk}C+U⊢tyvari⇒τi(1≤i≤k)C+U,τ(k)t⊢conbind⇒VEt∈TyName(k)⟨C⊢datbind′⇒VE′,TE′∀(t′,VE′′)∈Ran TE′, t≠t′⟩C⊢tycon tyvarseq = conbind ⟨and datbind′⟩⇒ClosCVE ⟨+VE′⟩, {tycon↦(t,ClosCVE)} ⟨+TE′⟩\frac{\begin{array}{c}\tyvarseq = \tyrowvar^{(k)} \premsep U = \{\tyrowvar_1, \cdots, \tyrowvar_k\} \\ \jdg{C + U}{\tyvar_i}{\tau_i} \quad (1 \le i \le k) \\ \jdg{C + U, \tau^{(k)}t}{\conbind}{\VE} \premsep t \in \TyName^{(k)} \\ \opt{\jdg{C}{\datbind'}{\VE', \TE'} \premsep \forall (t', \VE'') \in \Ran\TE',\ t \neq t'}\end{array}}{\begin{array}{c}C \vdash \tycon\ \tyvarseq\ \kw{=}\ \conbind\ \opt{\kw{and}\ \datbind'} \Rightarrow \\ \qquad \Clos_C \VE\ \opt{{}+ \VE'},\ \{\tycon \mapsto (t, \Clos_C \VE)\}\ \opt{{}+ \TE'}\end{array}}
(61)
Read it in its chapter·Permanent address: /standard/rules/sm-datbind

Comments

The parameters are made explicit while the constructors elaborate, and are generalised by the closure, since UofC=∅U \of C = \emptyset at the top level. A parameter need not occur in conbind\conbind, so phantom types are allowed. A parameter used as the extension variable of a record type is a row variable; τi\tau_i is then the open record type with no fields of its own, and an argument of tt in that position is a record type. The side condition t≠t′t \neq t' gives the custom types of one group distinct type names; rule (57) makes them new. The syntactic restrictions ensure that Dom VE∩Dom VE′=∅\Dom\VE \cap \Dom\VE' = \emptyset and tycon∉Dom TE′\tycon \notin \Dom\TE'.

Referred to from

TeX source
\defnrule[r:sm-datbind]
  {\tyvarseq = \tyrowvar^{(k)} \premsep U = \{\tyrowvar_1, \cdots, \tyrowvar_k\} \\ \jdg{C + U}{\tyvar_i}{\tau_i} \quad (1 \le i \le k) \\ \jdg{C + U, \tau^{(k)}t}{\conbind}{\VE} \premsep t \in \TyName^{(k)} \\ \opt{\jdg{C}{\datbind'}{\VE', \TE'} \premsep \forall (t', \VE'') \in \Ran\TE',\ t \neq t'}}
  {C \vdash \tycon\ \tyvarseq\ \kw{=}\ \conbind\ \opt{\kw{and}\ \datbind'} \Rightarrow \\ \qquad \Clos_C \VE\ \opt{{}+ \VE'},\ \{\tycon \mapsto (t, \Clos_C \VE)\}\ \opt{{}+ \TE'}}

Tests (18)

  • elm / CaseTreeTest
    A case expression on a recursive custom type, a binary tree, drives a recursive function that counts the tree's nodes.
  • elm / CustomTypeNestedTest
    A value of a recursive, parameterised custom type (a binary tree with values in its leaves) can be built several levels deep and logged.
  • elm / EitherTypeTest
    A custom type with two type parameters and one constructor for each can be built, mapped and pattern-matched.
  • elm / LetNumberCustomTriple3Test
    A single-constructor type whose three fields share one type variable, built from number literals in an unannotated `let` and matched by `case` with every field used as a Float: `round 45 + round 60 + round 75` gives 180.
  • elm / LetNumberCustomTypeTest
    A let-bound custom type value whose type parameter is `number`, built from an integer literal, has its payload extracted by `case` and multiplied by a `Float`.
  • elm / LetNumberNestedCustomTest
    An integer literal nested two custom-type constructors deep is used as a `Float`: `Box (NumBox 30)`, matched by the pattern `Box (NumBox n)` and multiplied by `1.5`, logs 45.
  • elm / LetNumberUnionBranchTest
    Integer literals carried by a constructor of a two-constructor custom type with a `number` type parameter are used as `Float`s: `Pair 30 40`, matched by `Pair a b` and computing `round (a * 1.5 + b * 2.5)`, logs 145.
  • elm / PhantomTypeVarTest
    Tests a custom type with a type parameter that one of its constructors does not use, rebuilt at a new type by generic functions.
  • elm / PolyChainCallTest
    Tests a polymorphic function that calls another polymorphic function twice, building a binary tree of two nodes that is then counted.
  • elm / RecursiveMutualTypeTest
    A pair of mutually recursive custom types, `Forest` and `RoseTree`, can be built and traversed.
  • elm / RecursiveTreeTest
    A recursive binary tree type can be summed and measured with recursive functions.
  • elm / StandardA98TypeBeforeAliasStringMismatchTest
    A custom type declared before a local alias spelt like an imported type uses the local alias.
  • elm / StandardA98TypeBeforeAliasTest
    A custom type may mention a local alias declared after it, even one spelt like an imported type.
  • elm / TailRecCustomCaseTest
    A self tail-recursive function that matches on a user-defined list type and destructures its `Cons` constructor gives the right result: summing `Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil)))` is 10.
  • elm / TypeMismatchDifferentlyNamedComparableVarsTest
    A list of two tuples whose first components are values of different custom types is rejected with a TYPE MISMATCH, where the second components are functions annotated with differently named `comparable` variables.
  • elm / TypeMismatchDifferentlyNamedFlexVarsTest
    A list of two tuples whose first components are values of different custom types is rejected with a TYPE MISMATCH, where the second components are functions annotated with differently named type variables.
  • elm / TypeMismatchLocalTypeNamedLikeAnImportedOneTest
    A local type named `Maybe` is a different type from the core `Maybe`, so mixing them is rejected with a TYPE MISMATCH.
  • elm / TypeMismatchTwoComparableVarsTest
    A list mixing tuples whose first components have different custom types is rejected with a TYPE MISMATCH.

Discussions

Discuss this rule·Search the discussions on GitHub

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