Elm Exactly

Rule 101d-atpat-tuple

Atomic PatternsE,v⊢atpat⇒VE/FAIL\jdgv{E}{v}{\atpat}{\VE/\FAIL}
v=(v1,v2⟨,v3⟩)E,v1⊢pat1⇒VE1/FAILE,v2⊢pat2⇒VE2/FAIL⟨E,v3⊢pat3⇒VE3/FAIL⟩E,v⊢(pat1, pat2 ⟨, pat3⟩)⇒VE1/FAIL+VE2/FAIL⟨+ VE3/FAIL⟩\frac{\begin{array}{c}v=(v_1,v_2\opt{,v_3})\premsep \jdgv{E}{v_1}{\pat_1}{\VE_1/\FAIL}\\ \jdgv{E}{v_2}{\pat_2}{\VE_2/\FAIL}\premsep \opt{\jdgv{E}{v_3}{\pat_3}{\VE_3/\FAIL}}\end{array}}{\begin{array}{c}\jdgv{E}{v}{\kw{(}\pat_1\kw{,}\ \pat_2\ \opt{\kw{,}\ \pat_3}\kw{)}} {\VE_1/\FAIL+\VE_2/\FAIL\opt{+\,\VE_3/\FAIL}}\end{array}}
(101)
Read it in its chapter·Permanent address: /standard/rules/d-atpat-tuple

Referred to from

TeX source
\defnrule[r:d-atpat-tuple]
  {v=(v_1,v_2\opt{,v_3})\premsep
   \jdgv{E}{v_1}{\pat_1}{\VE_1/\FAIL}\\
   \jdgv{E}{v_2}{\pat_2}{\VE_2/\FAIL}\premsep
   \opt{\jdgv{E}{v_3}{\pat_3}{\VE_3/\FAIL}}}
  {\jdgv{E}{v}{\kw{(}\pat_1\kw{,}\ \pat_2\ \opt{\kw{,}\ \pat_3}\kw{)}}
        {\VE_1/\FAIL+\VE_2/\FAIL\opt{+\,\VE_3/\FAIL}}}

Tests (29)

  • elm / CaseMaybePairTest
    Checks that a `case` on a tuple of two `Maybe Int` values, with one branch for each of the four `Just`/`Nothing` combinations, picks the right branch and binds the right values in each.
  • elm / CaseNestedCtorTest
    Checks that constructor patterns can nest: a constructor pattern inside another (`Container (Wrap n)`), and a tuple pattern inside a constructor (`Box ( a, x )`).
  • elm / CaseTripleTest
    A case expression on a 3-tuple of `Int`s matches literal and wildcard patterns in order, taking the first branch that fits.
  • elm / CaseTupleLiteralTest
    A case expression on a pair of `Int`s matches literal and wildcard patterns in order, so a pair that fits several patterns takes the first.
  • elm / CaseTupleTest
    A case expression on a pair of `Int`s matches literal and wildcard patterns in order, taking the first branch that fits.
  • elm / CharAstralTupleTest
    An astral `Char` (code point above 0xFFFF) in a pair and in a 3-tuple keeps its code point when read back with a tuple pattern, in a function's argument and in a destructuring `let`. How `Debug.log` prints such tuples is checked by `CharAstralTupleShowTest`.
  • elm / CharLiteralPatternMatchMinimalTest
    A Char literal pattern for the double quote `'"'` matches at increasing depths of nesting: bare, inside a tuple, inside a `Maybe`, and inside a `Maybe ( Char, String )`.
  • elm / ClosureCaptureRecordTest
    A lambda returned from a function can use a captured record's fields, or the elements of a captured tuple bound by a `case` pattern.
  • elm / CovLambdaSetFunctionsDestructuredFromTuplesAndRecordsTest
    Lambdas taken out of a tuple and a record by destructuring `let` patterns, put in a list and applied in turn.
  • elm / DecisionTreeAdvancedDeepNestingWithFallbackTest
    A `case` on a pair of pairs whose first branch matches all-zero literals and whose second binds the first and last numbers falls through to the second branch.
  • elm / DeepNestStressTest
    Deeply nested lists, tuples, records and `let` expressions can be built and taken apart.
  • elm / DictMapStagedCaptureTest
    A two-argument function passed as a parameter and applied to both of its arguments inside a lambda that a mapping function calls with two arguments receives both of them.
  • 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 / EmbeddedNothingInTupleTest
    A tuple pattern in a `let` takes `Nothing` and `Just 42` back out of a pair, and each matches the right pattern.
  • elm / EqualityStringChainCaseTest
    A `case` on a `( String, Bool )` tuple with string-literal patterns selects the right branch, and direct `==` on strings gives the right answer, in the same module.
  • elm / EscapeTopLevelTupleTest
    A tuple defined as a top-level constant is destructured in a `let` pattern into its two components.
  • elm / FunctionAccumulatorFunctionLookupTest
    Looking up a function in a list of key and function pairs, and applying the function found, gives the right result.
  • elm / InlineDupLetNamesTest
    A function whose body does a `case` on a tuple of its arguments gives the right result when one call to it is passed as an argument to another.
  • elm / LambdaPatternArgTest
    Checks anonymous functions whose parameters are tuple, record and wildcard patterns.
  • elm / LetDestructTupleNestedTest
    Tuple patterns in `let` bindings: a flat pair, a pair of pairs destructured in one pattern, and a pair whose second part is bound by name and destructured by a later binding.
  • elm / LetDestructuringTest
    Tuple patterns in `let` bindings, for a pair and for a triple; the line labelled `head` logs the first element of the triple `(10, 20, 30)`.
  • elm / LetNumberMixedTupleSlotTest
    Two integer literals in a three-element tuple whose middle element is a `String` are each used as a `Float`: matching `( 30, "x", 40 )` against `( a, _, c )` and adding `round (a * 1.5)` to `round (c * 1.5)` logs 105.
  • elm / LetNumberNestedTupleTest
    Integer literals in the inner tuple of a nested tuple are used as `Float`s while the outer one stays an `Int`: matching `( ( 30, 40 ), 50 )` against `( ( a, b ), c )` and computing `round (a * 1.5) + round (b * 1.5) + c` logs 155.
  • elm / LetNumberTupleRecordNestTest
    An integer-literal record field and an integer-literal tuple element, from a record nested in a pair, are both used as `Float`s: matching `( { lo = 30 }, 40 )` against `( r, c )` and computing `round (r.lo * 1.5) + round (c * 1.5)` logs 105.
  • elm / LssGapTupleFn
    A function stored in a tuple is taken out by destructuring and called.
  • elm / MinimalTuplePatternTest
    A tuple pattern matches the components of a pair.
  • elm / PolyEscapePolymorphicFunctionExtractedFromTupleTest
    A function stored in a tuple and taken out again by a let-bound pattern-matching helper can be applied: `first ( id, 0 ) 42` evaluates to 42.
  • elm / StandardA99RecordPatternInTupleTest
    A record pattern inside the tuple pattern of a `let` binding.
  • elm / StandardA99RecordPatternLambdaTest
    A record pattern in a lambda inside a `let` binding that is copied.

Discussions

Discuss this rule·Search the discussions on GitHub

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