Rule 80d-exp-case
Expressions
(80)
Comments
There is no rule in which 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 / 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 / BoolShortCircuitParserIdiomTestA 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 / CaseBoolTestA case expression on a Bool with `True` and `False` branches selects the matching branch.
- elm / CaseDeepNestTestCase expressions on Int nested two and three levels deep, each with literal branches and a wildcard, reach the right innermost branch.
- elm / CaseDeeplyNestedTestCase expressions on `Maybe` nested three levels deep reach the right innermost branch.
- elm / CaseGuardLikeTestChecks that nested `case` expressions on `Bool` comparisons, used in place of guards, pick the right branch at each threshold.
- elm / CaseInLambdaTestChecks 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 / CaseInLetTestChecks 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 / CaseNestedTestChecks that a `case` on one `Maybe` with a further `case` on a second `Maybe` inside each branch reaches all four combinations correctly.
- elm / CaseReturnFunctionTestChecks 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 / CharAstralCustomFieldTestAn 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 / ClosureCapture06TestA two-argument function matches on a custom-type value holding two `Maybe String`s and then on each `Maybe` in turn.
- elm / ClosureDifferentClosuresPerIfBranchInsideACaseTestA 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 / CovLambdaBoundaryCaseBoundaryInARecursiveValueTestA top-level function defined as a lambda whose `case` returns a different lambda per branch, one of which calls the function recursively.
- elm / CovLambdaBoundaryCaseBoundaryUnderAFunctionAliasTestA function whose result type is a type alias for a function type, with a `case` that returns a different lambda per branch.
- elm / DebugLogLambdaBoundaryTestA `case` branch that returns a lambda whose parameter is named `log` can still call `Debug.log` inside that lambda.
- elm / EmbeddedReturnNothingTestA function that returns `Nothing` for one input and `Just` for another is consumed by a `case` in the caller.
- elm / FunctionAccumulatorFunctionLookupTestLooking up a function in a list of key and function pairs, and applying the function found, gives the right result.
- elm / FunctionValuesChosenByIfCaseAndTupleTestFunctions chosen at run time by `if`, `case` and a returned tuple are called correctly.
- elm / JoinpointABI23Majority3FlatTestChecks a function whose `case` branches each return a lambda for the rest of its arguments, called with all four arguments at once.
- elm / LambdaCaseBoundaryTestChecks functions whose body is a `case` on the first argument that returns a two-parameter lambda in each branch.
- elm / LetSeparatedStagingTestA function defined with fewer parameters than its annotated type returns, from different `case` branches, lambdas that take the remaining arguments in different groupings.
- elm / MinimalCaseTestA case expression with one rule whose pattern is a variable.
- elm / NestedCaseReturnTestA `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 / TailRecDeciderSearchTestA 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 / EqualityBoolCaseTestThe result of `==` on `Bool` operands drives a `case` on `True` and `False` correctly.
- elm-core / EqualityBoolIfTestThe result of `==` and `/=` on `Bool` operands drives an `if` expression correctly.
- elm-core / NotEqualBoolCaseTestThe result of `/=` on two `Bool` literals is matched by a `case` with `True` and `False` branches, for all four combinations of operands.
- 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-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.