Rule 43s-pat-con
Patterns
(43)
Comments
The instance must be a constructed type after exactly arguments, so a constructor in a pattern is applied to as many patterns as it takes. Thus a constructed pattern with too few or too many arguments does not elaborate. The syntactic restrictions ensure that the domains of the are disjoint.
Referred to from
- The comment on rule
s-atpat-con(Chapter 4) - The comment on rule
sm-typbind-record(Chapter 5)
TeX source
\defnrule[r:s-pat-con]
{C(\longcon) = (\sigma, \isc) \premsep \sigma \succ \tau_1 \rightarrow \cdots \rightarrow \tau_n \rightarrow \tau'^{(k)}t \\ \jdg{C}{\atpat_i}{(\VE_i, \tau_i)} \quad (1 \le i \le n)}
{\jdg{C}{\longcon\ \atpat_1 \cdots \atpat_n}{(\VE_1 + \cdots + \VE_n,\ \tau'^{(k)}t)}}Tests (16)
- elm / CaseCtorArgPatternTestA single-constructor custom type can be destructured by a pattern in a function parameter, as in `getId (Person id _)`.
- elm / CaseCustomTypeTestA case on a custom type whose constructors carry different numbers of arguments binds those arguments in each branch.
- elm / CaseFanOutShadowTestA function that destructures a custom type in its parameter and then cases on a `Result` combines the bound field with the `Ok` value, or returns -1 for `Err`.
- elm / CaseMultiFieldExtractTestChecks that a `case` on a custom type binds every argument of a two-argument and a four-argument constructor to the right variable.
- 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 / CaseSingleCtorBoolMultiTypeTestA case expression matches `True` and `False` literal patterns inside a single-constructor custom type wrapping a `Bool`, while another single-constructor type, wrapping an `Int`, is defined in the same module.
- elm / CaseSingleCtorBoolTestA case expression matches `True` and `False` literal patterns inside a single-constructor custom type wrapping a `Bool`.
- elm / CompilerIssue2146RoseLambdaPatternCrashTestA type error involving a lambda pattern on a custom type must be reported normally, not crash the compiler.
- 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 / CustomTypePatternTestFunctions that take apart a custom-type value with a constructor pattern in their argument extract the right field.
- elm / LssGapCtorScaleConstructors of arity one to four build values that pattern matches in function arguments take apart again.
- elm / MinimalConstructedPatternTestA constructor pattern with an argument matches and binds the argument.
- elm / TooFewArgsAConstructorPatternWithTooFewArgumentsTestA constructor pattern with fewer arguments than the constructor takes is rejected with a TOO FEW ARGS error.
- elm / TooManyArgsAConstructorPatternWithTooManyArgumentsTestA constructor pattern with more arguments than the constructor takes is rejected with a TOO MANY ARGS error.
- elm / TypeMismatchArgumentOfAFixedConstructorPatternTestA constructor pattern whose argument has the wrong type is rejected with a TYPE MISMATCH.
- elm / TypeMismatchConstructorPatternTestA `case` on the number `1` with a `Just a` branch is rejected with a TYPE MISMATCH, because the pattern is a `Maybe` and the value is a number.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:s-pat-con] 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.