Elm Exactly

Rule 167e-dec-record

DecodingDecτ(j)=v\Dec{\tau}(j)=v
j∈Str→finBValDom ϱ⊆Dom jDom r=Dom ϱDecϱ(lab)(j(lab))=r(lab) for each lab∈Dom ϱDec{ϱ}(j)=r\frac{\begin{array}{c}j\in\effStr\finmap\BVal\premsep\Dom\varrho\subseteq\Dom j\premsep \Dom r=\Dom\varrho\\ \Dec{\varrho(\lab)}(j(\lab))=r(\lab)\ \text{for each}\ \lab\in\Dom\varrho\end{array}}{\begin{array}{c}\Dec{\rec{\varrho}}(j)=r\end{array}}
(167)
Read it in its chapter·Permanent address: /standard/rules/e-dec-record

Comments

An object with further keys is accepted, and they are ignored; an object that lacks the key of a field does not decode. Which missing field an implementation reports, and how, is outside the definition.

TeX source
\defnrule[r:e-dec-record]
  {j\in\effStr\finmap\BVal\premsep\Dom\varrho\subseteq\Dom j\premsep
   \Dom r=\Dom\varrho\\
   \Dec{\varrho(\lab)}(j(\lab))=r(\lab)\ \text{for each}\ \lab\in\Dom\varrho}
  {\Dec{\rec{\varrho}}(j)=r}

Tests (4)

  • elm / FlagsRecordTest
    A `Platform.worker` whose flags are a record of an `Int`, a `String` and a `Bool` receives the decoded record in `init`.
  • elm / MinimalPipeRecordTest
    A pipe at `{ a : Int }`: the value the driver sends in comes back out.
  • elm / PortAliasEchoTest
    An outgoing port whose type is written through a type alias, `port echoOut : Out msg` with `type alias Out msg = Payload -> Cmd msg`, sends its record payload, and the record comes back unchanged through an incoming port.
  • elm / PortPipeRecordTest
    A JSON object received at a record type goes out with exactly the record's fields.

Discussions

Discuss this rule·Search the discussions on GitHub

Discussions are on GitHub; one about this rule has [r:e-dec-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.