Rule 73d-atexp-update
Atomic Expressions
(73)
Comments
By elaboration, , so the result has the fields of , with the values of the fields named in replaced. The record bound to is unaffected, there being no state.
TeX source
\defnrule[r:d-atexp-update]
{E(\var)=r\premsep\jdg{E}{\exprow}{r'}}
{\jdg{E}{\kw{\kwlb}\ \var\ \kw{|}\ \exprow\ \kw{\kwrb}}{r+r'}}Tests (13)
- elm / CharAstralRecordFieldTestAn astral `Char` (code point above 0xFFFF) in a record field keeps its code point, next to an `Int` field and after a record update, and a record holding one is equal to a record literal with the same fields.
- 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 / PapEtaCtorProbeTests point-free top-level functions defined by partially applying a two-argument function, stored in a constructor, pattern-matched back out and applied.
- 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 / RecordWithFunctionsTestFunctions stored in record fields can be called, composed and replaced with record update.
- elm / WideRecord33TestA record with 33 fields, cycling through `Int`, `Float`, `Char`, `String` and `Bool`, supports field access, record patterns, update, equality and printing.
- elm / WideRecord40TestA record with 40 fields, cycling through `Int`, `Float`, `Char`, `String` and `Bool`, supports field access, record patterns, update, equality and printing.
- elm / WideRecordPatternTestA record with 28 `Int` fields reads back correctly through field access, through a record pattern, and after a record update.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:d-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.