Elm Exactly

Rule 102d-atpat-nil

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

Tests (14)

  • elm / CaseListConsTest
    Checks that a recursive function matching a list against `[]` and `x :: xs` sums the empty list, a one-element list and a three-element list correctly.
  • elm / CaseListTest
    Checks that a `case` on a `List` distinguishes the empty list, a list of exactly one element (`[_]`) and any longer list (`_`).
  • elm / CaseMixedPatternTest
    Checks that a single `case` can match a custom type constructor whose argument is itself matched as a list, with `x :: _` and `[]` patterns nested inside the constructor pattern.
  • elm / EmbeddedNilCaptureTest
    A local function that refers to an empty list defined in the enclosing `let` matches it against the `[]` pattern.
  • elm / EmbeddedNilRecursiveTest
    A recursive function that returns `[]` for an empty list builds the doubled positive elements of its input, skipping the rest.
  • elm / EmbeddedNothingRecursiveTest
    A recursive list search returns `Just` the first matching element, or `Nothing` once it reaches the end of the list.
  • elm / EmbeddedReturnNilTest
    A recursive filter returns the empty list when no element passes, and the caller receives it like any other list.
  • elm / ErasedListSpecializationTest
    A polymorphic self-recursive `count : List a -> Int` gives the right length when called both on `List Int` values and on `[]`, whose element type nothing constrains.
  • elm / MinimalNilPatternTest
    The empty-list pattern matches the empty list.
  • elm / RecursiveListLengthTest
    A self-recursive function that pattern matches on `[]` and `_ :: rest` counts the elements of lists of length 0, 3 and 5.
  • elm / TailRecBoolCarryTest
    A self tail-recursive function that carries a `Bool` argument from one call to the next, and sets it from a branch inside a `case`, returns the right result.
  • elm / TailRecCaseDestructTest
    Self tail-recursive functions whose tail calls sit in a `case` branch that destructures a list with `x :: xs` give the right results.
  • elm / TailRecFoldlCaseTest
    A hand-written left fold, defined as a self tail-recursive local function in `main`'s `let` and matching on the list with `case`, sums `[ 1, 2, 3 ]` to 6.
  • elm / TailRecNestedCaseTest
    Self-recursive list functions whose tail call sits in an `if` branch or behind a `case` with several list patterns return the right results.

Discussions

Discuss this rule·Search the discussions on GitHub

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