Elm Exactly

Rule 112d-pat-as

PatternsE,v⊢pat⇒VE/FAIL\jdgv{E}{v}{\pat}{\VE/\FAIL}
E,v⊢pat⇒VE/FAILE,v⊢pat as var⇒VE/FAIL+{var↦v}\frac{\begin{array}{c}\jdgv{E}{v}{\pat}{\VE/\FAIL}\end{array}}{\begin{array}{c}\jdgv{E}{v}{\pat\ \kw{as}\ \var}{\VE/\FAIL+\{\var\mapsto v\}}\end{array}}
(112)
Read it in its chapter·Permanent address: /standard/rules/d-pat-as

Comments

By the syntactic restrictions, var\var is not bound by pat\pat, so the modification adds a binding and replaces none.

TeX source
\defnrule[r:d-pat-as]
  {\jdgv{E}{v}{\pat}{\VE/\FAIL}}
  {\jdgv{E}{v}{\pat\ \kw{as}\ \var}{\VE/\FAIL+\{\var\mapsto v\}}}

Tests (7)

  • elm / CaseAsPatternTest
    An as-pattern in a case branch, `((x :: _) as whole)`, binds both the list head and the whole list.
  • elm / EdgeCaseAllDestructPatternsTest
    `let` bindings destructure a tuple, a record, a tuple returned by a `case`, and an `as` pattern, and each bound name has the expected value.
  • elm / LetDestructAliasTest
    A `let` destructuring with an `as` pattern binds both the parts and the whole: from `((a, b)) as pair = (1, 2)`, `pair` is `(1,2)` and `a` is 1.
  • elm / LetNumberAsPatternTest
    A tuple of number literals matched with an `as` pattern, where one part and the whole tuple are both used.
  • elm / MinimalAsPatternTest
    A layered pattern binds the whole value to its variable.
  • elm / StandardA99RecordPatternAsTest
    A record pattern under `as` in a `let` binding.
  • elm / StandardCoreEvaluationExamplesTest
    Small programs for rules of the dynamic semantics of the Core that other tests reach only in passing, and examples from the Comments of A Standard Definition of Elm?, Chapter 6.

Discussions

Discuss this rule·Search the discussions on GitHub

Discussions are on GitHub; one about this rule has [r:d-pat-as] 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.