Rule 9s-atexp-update
Atomic Expressions
(9)
Comments
The side conditions require the type of to be a record type that has every updated field, each at the type of its new value. The result has the type of , so an update neither adds a field nor changes the type of one: if has type then { r | x = "s" } does not elaborate. The type of may be open, so a function may update a field of any record that has it.
TeX source
\defnrule[r:s-atexp-update]
{\jdg{C}{\var}{\tau} \premsep \tau \in \RecType \premsep \jdg{C}{\exprow}{\varrho} \premsep \varrho \subseteq (\varrho \of \tau)}
{\jdg{C}{\kw{\kwlb}\ \var\ \kw{|}\ \exprow\ \kw{\kwrb}}{\tau}}Tests (16)
- elm / CompilerIssue1890RecordUpdateMutualRecursionCrashTestMutually recursive unannotated functions with a record update crash the compiler.
- elm / CompilerIssue2036LensRecordUpdateHangTestA lens whose setter takes its arguments in the wrong order must be a type error.
- elm / CompilerIssue2148RecordUpdateFoldrCrashTestA type error in a `foldr` over records must be reported normally, not crash the compiler.
- elm / CompilerIssue2206RecordUpdateLetCrashTestA type error in a record update inside a let crashes the compiler, depending on a binding's name.
- elm / CompilerIssue2214LensSetterArgumentOrderHangTestThe compiler rejects, with a type error, a lens record whose setter takes its arguments in the wrong order.
- elm / LetDestructFuncTupleTestA `let` destructures a pair of functions chosen by a `case`: a field accessor and a record-update lambda for the same field.
- elm / MinimalRecordUpdateTestA record update replaces the value of one field.
- elm / PolyEscapeRecordTestA record field holding a polymorphic identity function can be called, and a record update that replaces it with an increment function gives a record whose field calls the new function.
- elm / RecordChainedUpdateTestA record update can set several fields at once, and updates can be chained through let bindings.
- elm / RecordChainedUpdatesTestA record updated twice in a row, one field per update, keeps both changes.
- elm / RecordUpdatePolyFieldTestUpdating a function-typed field of a let-bound record whose function is polymorphic gives a record whose new function works.
- elm / RecordUpdateTestRecord update syntax produces a new record with one field changed and leaves the original unchanged.
- elm / TypeMismatchUpdateOfANearFieldTestA record update that sets a misspelt field, `cuont` on a record whose only field is `count`, is rejected with a TYPE MISMATCH error.
- elm / TypeMismatchUpdateOfANumberTestA record update applied to an `Int`, `{ n | x = 1 }` with `n : Int`, is rejected with a TYPE MISMATCH error.
- elm / TypeMismatchUpdateOfAnEmptyRecordTestA record update that sets field `x` on the empty record `{}` is rejected with a TYPE MISMATCH error.
- elm / TypeMismatchUpdateValueTestA record update that gives an `Int` field a `String`, `{ r | x = "s" }` with `r : { x : Int }`, is rejected with a TYPE MISMATCH error.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:s-atexp-update] 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.