Rule 98d-atpat-con
Atomic Patterns
(98)
TeX source
\defnrule[r:d-atpat-con]
{E(\longcon)=\con\premsep v=\con}
{\jdgv{E}{v}{\longcon}{\emptymap}}Tests (36)
- 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 / CaseBoolTestA case expression on a Bool with `True` and `False` branches selects the matching branch.
- elm / CaseCustomType4TestA case on a custom type with four constructors and no arguments, with one branch per constructor, selects the right branch for each.
- elm / CaseCustomType4WildcardTestA case on a four-constructor custom type with two explicit branches and a wildcard sends the other two constructors to the wildcard.
- 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 / 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 / CaseMaybeTestChecks that a `case` on a `Maybe Int` returns the wrapped value for `Just` and a default of -1 for `Nothing`.
- elm / CaseNestedRecordAccessTestChecks a function that destructures a constructor in its argument and then cases on a looked-up value, calling another function that also destructures a constructor argument and cases on a record field.
- 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 / CaseOrderTestChecks that a `case` on an `Order` maps each of `LT`, `EQ` and `GT` to its own string, using the results of `compare` on `Int` values.
- elm / CaseTreeTestA case expression on a recursive custom type, a binary tree, drives a recursive function that counts the tree's nodes.
- elm / EmbeddedNothingCallbackTestA function that pattern-matches a `Maybe` returns `Nothing` for `Nothing` and applies its function argument to a `Just` payload.
- elm / EmbeddedNothingCaptureTestA local function that refers to a `Nothing` defined in the enclosing `let` matches it against the `Nothing` pattern.
- elm / EmbeddedNothingInCustomTypeTestA `Nothing` stored in a custom type constructor and taken back out by a `case` still matches the `Nothing` pattern.
- elm / EmbeddedNothingInRecordTestA `Nothing` stored in a record field and read back with `.value` matches the `Nothing` pattern.
- elm / EmbeddedNothingInTupleTestA tuple pattern in a `let` takes `Nothing` and `Just 42` back out of a pair, and each matches the right pattern.
- elm / EmbeddedNothingMapTestA local `map` with a function that matches `Maybe` maps each `Nothing` to -1 and each `Just` to its payload.
- elm / EmbeddedReturnNothingTestA function that returns `Nothing` for one input and `Just` for another is consumed by a `case` in the caller.
- elm / EscapeCustomCaseScrutineeTestA value of a user-defined custom type, built in the call and taken apart by a `case` in another function, yields its payload.
- elm / LambdaCaseBoundaryTestChecks functions whose body is a `case` on the first argument that returns a two-parameter lambda in each branch.
- elm / MaybePatternMatchTestA `case` on a `Maybe` takes the `Just` branch to extract the value and the `Nothing` branch otherwise.
- elm / MinimalConstructorPatternTestA constructor pattern without arguments matches its constructor.
- elm / SingleCtorPairBoolCharTestPattern matching works on two single-constructor types in one module, one wrapping a `Bool` and one wrapping a `Char`.
- elm / SingleCtorPairBoolFloatTestPattern matching works on two single-constructor types in one module, one wrapping a `Bool` and one wrapping a `Float`.
- elm / SingleCtorPairBoolIntBidiTestPattern matching and value extraction both work on two single-constructor types in one module, one wrapping a `Bool` and one wrapping an `Int`.
- elm / SingleCtorPairFloatBoolTestPattern matching works on two single-constructor types in one module, one wrapping a `Float` and one wrapping a `Bool`.
- elm / SingleCtorPairStringBoolTestPattern matching works on two single-constructor types in one module, one wrapping a `String` and one wrapping a `Bool`.
- elm / TailRecCustomCaseTestA self tail-recursive function that matches on a user-defined list type and destructures its `Cons` constructor gives the right result: summing `Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil)))` is 10.
- elm / TailRecMultiCaseWhileTestA tail-recursive fold over a list of custom-type values, with a `case` on string literals nested inside one list pattern and tail calls in every branch, accumulates the right pair of totals.
- elm / UserBoolNamedCtorTestA custom type may name its own constructors `True` and `False`, and they behave as ordinary constructors, distinct from each other and from `Unknown`.
- 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-atpat-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.