Rule 101d-atpat-tuple
Atomic Patterns
(101)
Referred to from
- The comment on rule
d-atpat-unit(Chapter 6)
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 / CaseMaybePairTestChecks 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 / CaseNestedCtorTestChecks that constructor patterns can nest: a constructor pattern inside another (`Container (Wrap n)`), and a tuple pattern inside a constructor (`Box ( a, x )`).
- elm / CaseTripleTestA case expression on a 3-tuple of `Int`s matches literal and wildcard patterns in order, taking the first branch that fits.
- elm / CaseTupleLiteralTestA 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 / CaseTupleTestA case expression on a pair of `Int`s matches literal and wildcard patterns in order, taking the first branch that fits.
- elm / CharAstralTupleTestAn 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 / CharLiteralPatternMatchMinimalTestA 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 / ClosureCaptureRecordTestA 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 / CovLambdaSetFunctionsDestructuredFromTuplesAndRecordsTestLambdas taken out of a tuple and a record by destructuring `let` patterns, put in a list and applied in turn.
- elm / DecisionTreeAdvancedDeepNestingWithFallbackTestA `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 / DeepNestStressTestDeeply nested lists, tuples, records and `let` expressions can be built and taken apart.
- elm / DictMapStagedCaptureTestA 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 / EmbeddedNothingInTupleTestA tuple pattern in a `let` takes `Nothing` and `Just 42` back out of a pair, and each matches the right pattern.
- elm / EqualityStringChainCaseTestA `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 / EscapeTopLevelTupleTestA tuple defined as a top-level constant is destructured in a `let` pattern into its two components.
- elm / FunctionAccumulatorFunctionLookupTestLooking up a function in a list of key and function pairs, and applying the function found, gives the right result.
- elm / InlineDupLetNamesTestA 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 / LambdaPatternArgTestChecks anonymous functions whose parameters are tuple, record and wildcard patterns.
- elm / LetDestructTupleNestedTestTuple 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 / LetDestructuringTestTuple 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 / LetNumberMixedTupleSlotTestTwo 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 / LetNumberNestedTupleTestInteger 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 / LetNumberTupleRecordNestTestAn 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 / LssGapTupleFnA function stored in a tuple is taken out by destructuring and called.
- elm / MinimalTuplePatternTestA tuple pattern matches the components of a pair.
- elm / PolyEscapePolymorphicFunctionExtractedFromTupleTestA 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 / StandardA99RecordPatternInTupleTestA record pattern inside the tuple pattern of a `let` binding.
- elm / StandardA99RecordPatternLambdaTestA 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.