Rule 85d-match-first
Matches
(85)
Comments
The value being matched stands to the left of the turnstile. The match rules are tried in the order written, and the first whose pattern matches gives the result; the match rules after it are not evaluated, even when their patterns would also match. This order is part of the meaning, and is unaffected by the freedom of evaluation order (Section 6.7), since a rule for a later match rule requires every earlier one to give FAIL.
TeX source
\defnrule[r:d-match-first]
{\jdgv{E}{v}{\mrule}{v'}}
{\jdgv{E}{v}{\mrule\ \opt{\kw{;}\ \match}}{v'}}Tests (10)
- elm / BoolAndTestThe `&&` operator gives `True` only when both operands are `True`, checked over all four combinations.
- elm / BoolOrTestThe `||` operator gives `False` only when both operands are `False`, checked over all four combinations.
- elm / CaseListThreeWayTestChecks that a `case` on a `List` with `[]`, `[x]` and `x :: xs` patterns, in that order, sends a one-element list to `[x]` rather than to the cons pattern.
- 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 / MinimalCaseTestA case expression with one rule whose pattern is a variable.
- elm / TailRecNestedCaseTestSelf-recursive list functions whose tail call sits in an `if` branch or behind a `case` with several list patterns return the right results.
- elm-core / EqualityBoolIfTestThe result of `==` and `/=` on `Bool` operands drives an `if` expression correctly.
- elm-core / NotEqualBoolIfTestThe result of `/=` on two `Bool` literals is used as the condition of an `if`, for all four combinations of operands; each logs `"yes"` exactly when the operands differ.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:d-match-first] 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.