Elm Exactly

Rule 73d-atexp-update

Atomic ExpressionsE⊢atexp⇒v\jdg{E}{\atexp}{v}
E(var)=rE⊢exprow⇒r′E⊢{ var | exprow }⇒r+r′\frac{\begin{array}{c}E(\var)=r\premsep\jdg{E}{\exprow}{r'}\end{array}}{\begin{array}{c}\jdg{E}{\kw{\kwlb}\ \var\ \kw{|}\ \exprow\ \kw{\kwrb}}{r+r'}\end{array}}
(73)
Read it in its chapter·Permanent address: /standard/rules/d-atexp-update

Comments

By elaboration, Dom r′⊆Dom r\Dom r'\subseteq\Dom r, so the result has the fields of rr, with the values of the fields named in exprow\exprow replaced. The record bound to var\var 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 / CharAstralRecordFieldTest
    An 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 / LetDestructFuncTupleTest
    A `let` destructures a pair of functions chosen by a `case`: a field accessor and a record-update lambda for the same field.
  • elm / MinimalRecordUpdateTest
    A record update replaces the value of one field.
  • elm / PapEtaCtorProbe
    Tests point-free top-level functions defined by partially applying a two-argument function, stored in a constructor, pattern-matched back out and applied.
  • elm / PolyEscapeRecordTest
    A 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 / RecordChainedUpdateTest
    A record update can set several fields at once, and updates can be chained through let bindings.
  • elm / RecordChainedUpdatesTest
    A record updated twice in a row, one field per update, keeps both changes.
  • elm / RecordUpdatePolyFieldTest
    Updating a function-typed field of a let-bound record whose function is polymorphic gives a record whose new function works.
  • elm / RecordUpdateTest
    Record update syntax produces a new record with one field changed and leaves the original unchanged.
  • elm / RecordWithFunctionsTest
    Functions stored in record fields can be called, composed and replaced with record update.
  • elm / WideRecord33Test
    A record with 33 fields, cycling through `Int`, `Float`, `Char`, `String` and `Bool`, supports field access, record patterns, update, equality and printing.
  • elm / WideRecord40Test
    A record with 40 fields, cycling through `Int`, `Float`, `Char`, `String` and `Bool`, supports field access, record patterns, update, equality and printing.
  • elm / WideRecordPatternTest
    A 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.