Rule 37s-atpat-tuple
Atomic Patterns
(37)
Comments
By the grammar is 2 or 3, and by the syntactic restrictions the domains of the are disjoint.
TeX source
\defnrule[r:s-atpat-tuple]
{\jdg{C}{\pat_i}{(\VE_i, \tau_i)} \quad (1 \le i \le k)}
{\jdg{C}{\kw{(}\,\pat_1\kw{,}\ \cdots\kw{,}\ \pat_k\,\kw{)}}{(\VE_1 + \cdots + \VE_k,\ (\tau_1, \cdots, \tau_k)\tTuple{k})}}Tests (12)
- 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 / CovPatternSplitTupleAndConstructorParametersMatchedByCaseTestFunctions that take a tuple or a custom-type value as their parameter and take it apart with `case`, including literal patterns (`( 0, b )`, `Q True n`) and a `Float` component.
- elm / CovTailRecPairParameterPassedUnchangedLetBoundAndRebuiltTestSelf tail-recursive functions with a pair parameter that is destructured in a `let`, then passed on unchanged, rebuilt with its components swapped, or replaced by a `let`-bound pair.
- elm / CovTailRecPairParametersSwappedAndALoopReturningALambdaTestSelf tail-recursive functions over pair parameters: one that swaps a pair's components or exchanges its two pair arguments, and one that returns a lambda in its base case.
- elm / CovTailRecSplitATripleParameterTestA self tail-recursive function that destructures a triple of `Int`, `Int` and `Float` in its parameter pattern and rebuilds it on each call.
- 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.
- elm / TypeMismatchDestructureTestDestructuring the number `1` with the tuple pattern `( a, b )` in a `let` is rejected with a TYPE MISMATCH.
- elm / TypeMismatchLambdaArgumentPatternTestApplying a lambda with a tuple pattern to a number is rejected with a TYPE MISMATCH.
- elm / TypeMismatchTupleComponentPatternTestA tuple pattern whose first component is a `String` literal, matched against a tuple of numbers, is rejected with a TYPE MISMATCH.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:s-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.