Rule 64sm-typbind-record
Alias Bindings
(64)
Comments
A record alias also defines a constructor, spelt as the alias, whose arguments are the fields in the order written: after type alias P = { y : Int, x : Int }, the expression P 1 2 denotes the record { y = 1, x = 2 }. Its status is , so it may be applied but may not occur in a pattern (rule (43)). It is exposed and imported together with the alias (rule (54)).
Referred to from
- The comment on rule
sm-topdec-types(Chapter 5) - The comment on rule
sm-typbind(Chapter 5) - Section 6.2 Number Specialisation
TeX source
\defnrule[r:sm-typbind-record]
{\tyvarseq = \tyrowvar^{(k)} \premsep \jdg{C + \{\tyrowvar_1, \cdots, \tyrowvar_k\}}{\ty}{\tau} \\ \smlabs(\ty) = \lab_1 \cdots \lab_n \premsep \tau = \rec{\varrho} \premsep \varrho = \{\lab_1 \mapsto \tau_1, \cdots, \lab_n \mapsto \tau_n\} \\ \con = \tycon \premsep \VE = \Clos_C \{\con \mapsto (\tau_1 \rightarrow \cdots \rightarrow \tau_n \rightarrow \tau, \isv)\}}
{\jdg{C}{\tycon\ \tyvarseq\ \kw{=}\ \ty}{\VE,\ \{\tycon \mapsto (\Lambda\tyrowvar^{(k)}.\tau, \VE)\}}}Tests (11)
- elm / CompilerIssue2036LensRecordUpdateHangTestA lens whose setter takes its arguments in the wrong order must be a type error.
- elm / CompilerIssue2214LensSetterArgumentOrderHangTestThe compiler rejects, with a type error, a lens record whose setter takes its arguments in the wrong order.
- elm / MinimalRecordAliasConstructorTestA record type alias declares a constructor.
- elm / RecordRowsTestRecord expressions, record types and record patterns are rows of fields.
- elm / TypeAliasCtorTestChecks 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 / TypeMismatchAliasWhereARecordTestA value of a record alias used where a record with a differently typed field is expected is rejected with a TYPE MISMATCH.
- elm / TypeMismatchParameterisedAliasTestGiving a `Box Int` where a `Box String` is annotated is rejected with a TYPE MISMATCH error.
- elm / TypeMismatchTwoAliasedRecordsTestA value of one record alias annotated as a different record alias is rejected with a TYPE MISMATCH.
- elm / WideRecordDecoder26TestA 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 / WideRecordDecoder30TestA 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 / WideRecordDecoder70TestA 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:sm-typbind-record] 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.