Rule 8s-atexp-record
Atomic Expressions
(8)
Comments
A record expression has a closed record type: its fields are exactly those written.
TeX source
\defnrule[r:s-atexp-record]
{\opt{\jdg{C}{\exprow}{\varrho}}}
{\jdg{C}{\kw{\kwlb}\,\opt{\exprow}\,\kw{\kwrb}}{\rec{\emptymap\opt{{}+\varrho}}}}Tests (11)
- elm / LetNumberFracRecordTestThe two `number` fields of a let-bound record literal are typed independently, one used as an `Int` and the other as a `Float`.
- elm / MinimalRecordTestA record expression with one field.
- elm / TypeMismatchAliasedRecordFieldOfTheWrongTypeTestA record whose field has the wrong type for its record alias annotation is rejected with a TYPE MISMATCH.
- elm / TypeMismatchClosedRecordWhereExtensibleTestPassing a record that lacks a field the result must have is rejected with a TYPE MISMATCH.
- elm / TypeMismatchExtensibleRecordGivenAClosedOneTestA function annotated to return the extensible record `{ r | name : Int }` but returning the record literal `{ name = 1 }` is rejected with a TYPE MISMATCH.
- elm / TypeMismatchExtensibleRecordMissingAFieldTestPassing `{ age = 1 }` to a function that takes `{ r | name : Int }` is rejected with a TYPE MISMATCH, because the record has no `name` field.
- elm / TypeMismatchRecordFieldExtraTestPassing the record `{ name = 1, age = 2 }` to a function annotated to take exactly `{ name : Int }` is rejected with a TYPE MISMATCH error.
- elm / TypeMismatchRecordFieldsMissingTestPassing the record `{ name = 1 }` to a function annotated to take `{ name : Int, age : Int, size : Int }` is rejected with a TYPE MISMATCH error, because the fields `age` and `size` are missing.
- elm / TypeMismatchRecordWhereEmptyClosedRecordTestA record with a field, given where the annotation says the empty record `{}`, is rejected with a TYPE MISMATCH.
- elm / TypeMismatchRigidNumberAsRecordTestReturning a record where the annotation promises a `number` is rejected with a TYPE MISMATCH.
- elm / TypeMismatchRigidVarAsRecordTestA function annotated `a -> a` that returns a record 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:s-atexp-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.