Elm Exactly

Rule 80d-exp-case

ExpressionsE⊢exp⇒v\jdg{E}{\expm}{v}
E⊢exp⇒vE,v⊢match⇒v′E⊢case exp of match⇒v′\frac{\begin{array}{c}\jdg{E}{\expm}{v}\premsep\jdgv{E}{v}{\match}{v'}\end{array}}{\begin{array}{c}\jdg{E}{\kw{case}\ \expm\ \kw{of}\ \match}{v'}\end{array}}
(80)
Read it in its chapter·Permanent address: /standard/rules/d-exp-case

Comments

There is no rule in which match\match gives FAIL: the static semantics requires every match of a case to be exhaustive (Chapter 4), so for a value of the right type some match rule applies.

TeX source
\defnrule[r:d-exp-case]
  {\jdg{E}{\expm}{v}\premsep\jdgv{E}{v}{\match}{v'}}
  {\jdg{E}{\kw{case}\ \expm\ \kw{of}\ \match}{v'}}

Tests (31)

  • elm / BoolAndTest
    The `&&` operator gives `True` only when both operands are `True`, checked over all four combinations.
  • elm / BoolOrTest
    The `||` operator gives `False` only when both operands are `False`, checked over all four combinations.
  • elm / BoolShortCircuitParserIdiomTest
    A bounds check guarding an indexing call with `&&` (`idx < length src && unsafeIndex src idx /= ...`) stops the call from running past the end of the input.
  • elm / BoolShortCircuitTest
    `&&` and `||` short-circuit: `False && x` and `True || x` never evaluate `x`.
  • elm / CaseBoolTest
    A case expression on a Bool with `True` and `False` branches selects the matching branch.
  • elm / CaseDeepNestTest
    Case expressions on Int nested two and three levels deep, each with literal branches and a wildcard, reach the right innermost branch.
  • elm / CaseDeeplyNestedTest
    Case expressions on `Maybe` nested three levels deep reach the right innermost branch.
  • elm / CaseGuardLikeTest
    Checks that nested `case` expressions on `Bool` comparisons, used in place of guards, pick the right branch at each threshold.
  • elm / CaseInLambdaTest
    Checks that a `case` expression on a `Bool` inside an anonymous function evaluates correctly, both when the lambda is bound to a name and when it is passed straight to another function.
  • elm / CaseInLetTest
    Checks that a `case` expression on an `Order` can be the body of a `let` binding, with each of `GT`, `EQ` and `LT` selecting its own string.
  • elm / CaseNestedTest
    Checks that a `case` on one `Maybe` with a further `case` on a second `Maybe` inside each branch reaches all four combinations correctly.
  • elm / CaseReturnFunctionTest
    Checks that the branches of a `case` can each return a two-argument lambda, and that the returned function is applied with the right arithmetic.
  • elm / CharAstralCustomFieldTest
    An astral `Char` (code point above 0xFFFF) stored in a custom-type constructor's field keeps its code point when read back by pattern matching.
  • elm / ClosureCapture06Test
    A two-argument function matches on a custom-type value holding two `Maybe String`s and then on each `Maybe` in turn.
  • elm / ClosureDifferentClosuresPerIfBranchInsideACaseTest
    A function whose body is a `case` containing an `if` chain returns a different lambda from each branch, and the chosen lambda is applied to a further argument.
  • elm / CovLambdaBoundaryCaseBoundaryInARecursiveValueTest
    A top-level function defined as a lambda whose `case` returns a different lambda per branch, one of which calls the function recursively.
  • elm / CovLambdaBoundaryCaseBoundaryUnderAFunctionAliasTest
    A function whose result type is a type alias for a function type, with a `case` that returns a different lambda per branch.
  • elm / DebugLogLambdaBoundaryTest
    A `case` branch that returns a lambda whose parameter is named `log` can still call `Debug.log` inside that lambda.
  • elm / EmbeddedReturnNothingTest
    A function that returns `Nothing` for one input and `Just` for another is consumed by a `case` in the caller.
  • elm / FunctionAccumulatorFunctionLookupTest
    Looking up a function in a list of key and function pairs, and applying the function found, gives the right result.
  • elm / FunctionValuesChosenByIfCaseAndTupleTest
    Functions chosen at run time by `if`, `case` and a returned tuple are called correctly.
  • elm / JoinpointABI23Majority3FlatTest
    Checks a function whose `case` branches each return a lambda for the rest of its arguments, called with all four arguments at once.
  • elm / LambdaCaseBoundaryTest
    Checks functions whose body is a `case` on the first argument that returns a two-parameter lambda in each branch.
  • elm / LetSeparatedStagingTest
    A function defined with fewer parameters than its annotated type returns, from different `case` branches, lambdas that take the remaining arguments in different groupings.
  • elm / MinimalCaseTest
    A case expression with one rule whose pattern is a variable.
  • elm / NestedCaseReturnTest
    A `case` on a custom type whose branches return the result of another `case` on a String, either inline or through a helper, returns the right string.
  • elm / TailRecDeciderSearchTest
    A local function defined in a `let` that calls itself both in a tail position and in a non-tail position, as the scrutinee of a `case`, gives the right result.
  • elm-core / EqualityBoolCaseTest
    The result of `==` on `Bool` operands drives a `case` on `True` and `False` correctly.
  • elm-core / EqualityBoolIfTest
    The result of `==` and `/=` on `Bool` operands drives an `if` expression correctly.
  • elm-core / NotEqualBoolCaseTest
    The result of `/=` on two `Bool` literals is matched by a `case` with `True` and `False` branches, for all four combinations of operands.
  • elm-core / NotEqualBoolIfTest
    The 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-exp-case] 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.