Elm Exactly

Rule 95d-atpat-scon

Atomic PatternsE,v⊢atpat⇒VE/FAIL\jdgv{E}{v}{\atpat}{\VE/\FAIL}
v=val(scon)E,v⊢scon⇒{}\frac{\begin{array}{c}v=\valof(\scon)\end{array}}{\begin{array}{c}\jdgv{E}{v}{\scon}{\emptymap}\end{array}}
(95)
Read it in its chapter·Permanent address: /standard/rules/d-atpat-scon

Comments

A constant in a pattern is an integer, character or string constant, never a floating-point one, so the test v=val(scon)v=\valof(\scon) is identity of special values. An integer constant matches the normalised integer it denotes.

TeX source
\defnrule[r:d-atpat-scon]
  {v=\valof(\scon)}
  {\jdgv{E}{v}{\scon}{\emptymap}}

Tests (32)

  • elm / AstralCharCasePatternTest
    A `case` on a `Char` matches a pattern above U+FFFF, `'\u{1F600}'`, against the same character written as an escape or as the character itself.
  • elm / CaseCharManyBranchTest
    A case on Char with ten literal branches (`'0'` to `'9'`) and a wildcard maps digit characters to their values and anything else to -1.
  • elm / CaseCharTest
    A case on Char with literal vowel branches and a wildcard picks the matching literal, falling back to the wildcard for other characters.
  • 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 / CaseDefaultTest
    A case on Int with one literal branch and a wildcard sends every other value to the wildcard.
  • elm / CaseIntTest
    Checks that a `case` on an `Int` matches integer literal patterns and falls through to the wildcard for any other value.
  • elm / CaseManyBranchesTest
    Checks that a `case` on an `Int` with seven literal branches and a wildcard selects the first, a middle and the last literal branch correctly.
  • elm / CaseReturningLambdaTest
    Checks a `case` on a custom type whose first branch holds a nested `case` on a `String`, where every branch of both returns a two-argument lambda.
  • elm / CaseSharedBranchTest
    Checks a `case` on a custom type whose first branch holds a nested `case` on the constructor's `String` argument.
  • elm / CaseStringEmptyPatternTest
    A case expression on a `String` matches the empty-string literal `""` alongside non-empty literal patterns and a wildcard.
  • elm / CaseStringEscapeTest
    A case expression on a `String` matches literal patterns written with escape sequences: a newline, a tab and a double quote.
  • elm / CaseStringManyBranchTest
    A case expression on a `String` with seven literal patterns (three-letter day abbreviations) and a wildcard selects the matching branch.
  • elm / CaseStringTest
    A case expression on a `String` with two literal patterns and a wildcard returns the `Int` of the matching branch.
  • elm / CaseUnicodeCharTest
    A case expression on a `Char` matches character literals outside ASCII: two Greek letters and a CJK ideograph.
  • elm / CharCasePredicateTest
    A `case` on a `Char` with several character-literal branches, including the escaped literal `'\\'`, selects the branch matching the scrutinee.
  • elm / CharLiteralPatternMatchMinimalTest
    A Char literal pattern for the double quote `'"'` matches at increasing depths of nesting: bare, inside a tuple, inside a `Maybe`, and inside a `Maybe ( Char, String )`.
  • elm / CharLiteralPatternMatchVariousTest
    A `case` on a Char literal matches a pattern for the same literal, for a double quote, `{`, `a`, a backslash, a newline, `0` and a space.
  • elm / EqualityStringChainCaseTest
    A `case` on a `( String, Bool )` tuple with string-literal patterns selects the right branch, and direct `==` on strings gives the right answer, in the same module.
  • 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 / LargeDispatchCaseTest
    Checks a `case` on a list of custom-type values whose branches contain a nested `case` on a String.
  • elm / MinimalConstantPatternTest
    A constant pattern matches the constant it spells.
  • 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 / StringCasePatternCommaTest
    Two `case` expressions on Strings, one of whose patterns contains a comma, each match against their own patterns.
  • elm / StringCreationMatrixTest
    The same string produced in different ways is `==`, and matches the same string pattern in a `case`.
  • elm / StringEscapeCrTest
    The `\r` escape in a string literal is a carriage return, code point 13.
  • elm / TailRecCaseMultiBranchTypesTest
    A self tail-recursive search whose outer `case` has one branch per constructor of a custom type at the head of a list, with a nested `case` on a `String` inside one branch, finds the right element.
  • elm / TailRecDecoderLoopTest
    A recursive function whose outer `case` is on a custom type and whose inner `case` is on a `String` returns the right result for each branch.
  • elm / TailRecManyBranchStringTest
    A self-recursive function over a three-constructor custom type, with a tail call in one branch and a `case` in another that matches a `String` against literal patterns, returns the right string.
  • 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 / TailRecNestedStringCaseTest
    A self-recursive function whose non-recursive branch matches a `String` against literal patterns returns the matched value after unwrapping several layers.
  • elm / TailRecTypeTraversalTest
    A function over a small type-expression tree, tail-recursive through its alias constructor and matching primitive type names as string literals, resolves an alias chain to the right name.

Discussions

Discuss this rule·Search the discussions on GitHub

Discussions are on GitHub; one about this rule has [r:d-atpat-scon] 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.