Elm Exactly

Rule 98d-atpat-con

Atomic PatternsE,v⊢atpat⇒VE/FAIL\jdgv{E}{v}{\atpat}{\VE/\FAIL}
E(longcon)=conv=conE,v⊢longcon⇒{}\frac{\begin{array}{c}E(\longcon)=\con\premsep v=\con\end{array}}{\begin{array}{c}\jdgv{E}{v}{\longcon}{\emptymap}\end{array}}
(98)
Read it in its chapter·Permanent address: /standard/rules/d-atpat-con
TeX source
\defnrule[r:d-atpat-con]
  {E(\longcon)=\con\premsep v=\con}
  {\jdgv{E}{v}{\longcon}{\emptymap}}

Tests (36)

  • 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 / CaseBoolTest
    A case expression on a Bool with `True` and `False` branches selects the matching branch.
  • elm / CaseCustomType4Test
    A case on a custom type with four constructors and no arguments, with one branch per constructor, selects the right branch for each.
  • elm / CaseCustomType4WildcardTest
    A case on a four-constructor custom type with two explicit branches and a wildcard sends the other two constructors to the wildcard.
  • 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 / 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 / CaseMaybeTest
    Checks that a `case` on a `Maybe Int` returns the wrapped value for `Just` and a default of -1 for `Nothing`.
  • elm / CaseNestedRecordAccessTest
    Checks 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 / 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 / CaseOrderTest
    Checks 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 / CaseTreeTest
    A case expression on a recursive custom type, a binary tree, drives a recursive function that counts the tree's nodes.
  • elm / EmbeddedNothingCallbackTest
    A function that pattern-matches a `Maybe` returns `Nothing` for `Nothing` and applies its function argument to a `Just` payload.
  • elm / EmbeddedNothingCaptureTest
    A local function that refers to a `Nothing` defined in the enclosing `let` matches it against the `Nothing` pattern.
  • elm / EmbeddedNothingInCustomTypeTest
    A `Nothing` stored in a custom type constructor and taken back out by a `case` still matches the `Nothing` pattern.
  • elm / EmbeddedNothingInRecordTest
    A `Nothing` stored in a record field and read back with `.value` matches the `Nothing` pattern.
  • elm / EmbeddedNothingInTupleTest
    A tuple pattern in a `let` takes `Nothing` and `Just 42` back out of a pair, and each matches the right pattern.
  • elm / EmbeddedNothingMapTest
    A local `map` with a function that matches `Maybe` maps each `Nothing` to -1 and each `Just` to its payload.
  • elm / EmbeddedReturnNothingTest
    A function that returns `Nothing` for one input and `Just` for another is consumed by a `case` in the caller.
  • elm / EscapeCustomCaseScrutineeTest
    A value of a user-defined custom type, built in the call and taken apart by a `case` in another function, yields its payload.
  • elm / LambdaCaseBoundaryTest
    Checks functions whose body is a `case` on the first argument that returns a two-parameter lambda in each branch.
  • elm / MaybePatternMatchTest
    A `case` on a `Maybe` takes the `Just` branch to extract the value and the `Nothing` branch otherwise.
  • elm / MinimalConstructorPatternTest
    A constructor pattern without arguments matches its constructor.
  • elm / SingleCtorPairBoolCharTest
    Pattern matching works on two single-constructor types in one module, one wrapping a `Bool` and one wrapping a `Char`.
  • elm / SingleCtorPairBoolFloatTest
    Pattern matching works on two single-constructor types in one module, one wrapping a `Bool` and one wrapping a `Float`.
  • elm / SingleCtorPairBoolIntBidiTest
    Pattern matching and value extraction both work on two single-constructor types in one module, one wrapping a `Bool` and one wrapping an `Int`.
  • elm / SingleCtorPairFloatBoolTest
    Pattern matching works on two single-constructor types in one module, one wrapping a `Float` and one wrapping a `Bool`.
  • elm / SingleCtorPairStringBoolTest
    Pattern matching works on two single-constructor types in one module, one wrapping a `String` and one wrapping a `Bool`.
  • elm / TailRecCustomCaseTest
    A 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 / TailRecMultiCaseWhileTest
    A 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 / UserBoolNamedCtorTest
    A 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 / 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-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.