Elm Exactly

Rule 132dm-typbind

Alias Bindings⊢typbind⇒(RA,VE)\jdg{}{\typbind}{(\dmRA,\VE)}
⟨con=tycon⟩⊢tycon ⟨= {lab1, ⋯, labn}⟩⇒(∅⟨∪ {tycon}⟩, {}⟨+ {con↦record(lab1⋯labn)}⟩)\frac{\begin{array}{c}\opt{\con=\tycon}\end{array}}{\begin{array}{c}\vdash\tycon\ \opt{\kw{=}\ \kw{\kwlb}\lab_1\kw{,}\ \cdots\kw{,}\ \lab_n\kw{\kwrb}}\\ \Rightarrow(\emptyset\opt{\cup\,\{\tycon\}},\ \emptymap\opt{+\,\{\con\mapsto\dmrecord(\lab_1\cdots\lab_n)\}})\end{array}}
(132)
Read it in its chapter·Permanent address: /standard/rules/dm-typbind

Comments

Here n≥0n\geq 0, and by the syntactic restrictions the labels are distinct. The constructor takes the fields in the order in which the alias writes them: with type alias P = { y : Int, x : Int }, P 1 2 evaluates to { y = 1, x = 2 }. An alias of the empty record binds its name to the empty record itself (Section 7.4). An alias of any other type binds nothing, and its type constructor is not in RA\dmRA; so rule (126) records in RA\dmRA exactly the record aliases.

TeX source
\defnrule[r:dm-typbind]
  {\opt{\con=\tycon}}
  {\vdash\tycon\ \opt{\kw{=}\ \kw{\kwlb}\lab_1\kw{,}\ \cdots\kw{,}\ \lab_n\kw{\kwrb}}\\
     \Rightarrow(\emptyset\opt{\cup\,\{\tycon\}},\ \emptymap\opt{+\,\{\con\mapsto\dmrecord(\lab_1\cdots\lab_n)\}})}

Tests (5)

  • elm / MinimalTypeAliasTest
    A type alias of a type name.
  • elm / TypeAliasCtorTest
    Checks that the name of a record type alias can be used as a function that builds the record, taking the fields in the order the alias declares them.
  • elm / WideRecordDecoder26Test
    A 26-field record alias, used as a constructor function, can be filled in one argument at a time by an `andMap` pipeline over `Maybe`.
  • elm / WideRecordDecoder30Test
    A 30-field record alias, used as a constructor function, can be filled in one argument at a time by an `andMap` pipeline over `Maybe`, with fields of different types near the end.
  • elm / WideRecordDecoder70Test
    A 70-field record alias, used as a constructor function, can be filled in one argument at a time by an `andMap` pipeline over `Maybe`.

Discussions

Discuss this rule·Search the discussions on GitHub

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