Elm Exactly
Results / elm-core /

ContainerEqualityStringTest

Tags:elm-spec

Checks, in A Standard Definition of Elm?:basis Basics.eq

Translated into Lean for the mechanisation of the book: see its Lean translation.

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
Checks `==` on pairs, triples and lists of `String`.

The cases that matter are empty strings, letter case, one string being a prefix
of another, and characters outside ASCII.

  - Pairs: equal, differing in either position, empty strings, differing only
    in case, `"app"` against `"apple"`, and non-ASCII contents.
  - Triples: equal, differing in the middle, containing empty strings, and
    Greek letters.
  - Lists: equal, different lengths, two empty lists, lists of empty strings,
    differing in case, and non-ASCII contents.

Results

elm-0.19.1

passran in 71 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
pairEqual: True
pairFirstDiff: False
pairSecondDiff: False
pairEmpty: True
pairCaseDiff: False
pairPrefixDiff: False
pairUnicode: True
tripleEqual: True
tripleMidDiff: False
tripleWithEmpty: True
tripleUnicode: True
listEqual: True
listLenDiff: False
listEmpty: True
listEmptyStrings: True
listCaseDiff: False
listUnicode: True

elm-0.19.2

passran in 62 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
pairEqual: True
pairFirstDiff: False
pairSecondDiff: False
pairEmpty: True
pairCaseDiff: False
pairPrefixDiff: False
pairUnicode: True
tripleEqual: True
tripleMidDiff: False
tripleWithEmpty: True
tripleUnicode: True
listEqual: True
listLenDiff: False
listEmpty: True
listEmptyStrings: True
listCaseDiff: False
listUnicode: True

elm-0.19.3

passran in 75 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
pairEqual: True
pairFirstDiff: False
pairSecondDiff: False
pairEmpty: True
pairCaseDiff: False
pairPrefixDiff: False
pairUnicode: True
tripleEqual: True
tripleMidDiff: False
tripleWithEmpty: True
tripleUnicode: True
listEqual: True
listLenDiff: False
listEmpty: True
listEmptyStrings: True
listCaseDiff: False
listUnicode: True

lamdera-1.5.0

passran in 46 ms
Output
pairEqual: True
pairFirstDiff: False
pairSecondDiff: False
pairEmpty: True
pairCaseDiff: False
pairPrefixDiff: False
pairUnicode: True
tripleEqual: True
tripleMidDiff: False
tripleWithEmpty: True
tripleUnicode: True
listEqual: True
listLenDiff: False
listEmpty: True
listEmptyStrings: True
listCaseDiff: False
listUnicode: True

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-core/ContainerEqualityStringTest] in its title.

Source

The -- CHECK: lines give the expected output.

module ContainerEqualityStringTest exposing (main)
{-| Checks `==` on pairs, triples and lists of `String`.
The cases that matter are empty strings, letter case, one string being a prefix
of another, and characters outside ASCII.
- Pairs: equal, differing in either position, empty strings, differing only
in case, `"app"` against `"apple"`, and non-ASCII contents.
- Triples: equal, differing in the middle, containing empty strings, and
Greek letters.
- Lists: equal, different lengths, two empty lists, lists of empty strings,
differing in case, and non-ASCII contents.
-}
-- TAGS: elm-spec, b:Basics.eq
-- CHECK: pairEqual: True
-- CHECK: pairFirstDiff: False
-- CHECK: pairSecondDiff: False
-- CHECK: pairEmpty: True
-- CHECK: pairCaseDiff: False
-- CHECK: pairPrefixDiff: False
-- CHECK: pairUnicode: True
-- CHECK: tripleEqual: True
-- CHECK: tripleMidDiff: False
-- CHECK: tripleWithEmpty: True
-- CHECK: tripleUnicode: True
-- CHECK: listEqual: True
-- CHECK: listLenDiff: False
-- CHECK: listEmpty: True
-- CHECK: listEmptyStrings: True
-- CHECK: listCaseDiff: False
-- CHECK: listUnicode: True
import Html exposing (text)
main =
let
emptyStrings : List String
emptyStrings = []
-- Tuple2 ---------------------------------------------------------
_ = Debug.log "pairEqual" (("apple", "banana") == ("apple", "banana"))
_ = Debug.log "pairFirstDiff" (("apple", "banana") == ("cherry", "banana"))
_ = Debug.log "pairSecondDiff" (("apple", "banana") == ("apple", "cherry"))
_ = Debug.log "pairEmpty" (("", "") == ("", ""))
_ = Debug.log "pairCaseDiff" (("Apple", "banana") == ("apple", "banana"))
_ = Debug.log "pairPrefixDiff" (("app", "x") == ("apple", "x"))
_ = Debug.log "pairUnicode" (("\u{03BB}x", "\u{20AC}y") == ("\u{03BB}x", "\u{20AC}y"))
-- Tuple3 ---------------------------------------------------------
_ = Debug.log "tripleEqual" (("a", "b", "c") == ("a", "b", "c"))
_ = Debug.log "tripleMidDiff" (("a", "b", "c") == ("a", "x", "c"))
_ = Debug.log "tripleWithEmpty" (("", "b", "") == ("", "b", ""))
_ = Debug.log "tripleUnicode" (("\u{03B1}", "\u{03B2}", "\u{03B3}") == ("\u{03B1}", "\u{03B2}", "\u{03B3}"))
-- List -----------------------------------------------------------
_ = Debug.log "listEqual" (["a", "b", "c"] == ["a", "b", "c"])
_ = Debug.log "listLenDiff" (["a", "b"] == ["a", "b", "c"])
_ = Debug.log "listEmpty" (emptyStrings == [])
_ = Debug.log "listEmptyStrings" (["", "", ""] == ["", "", ""])
_ = Debug.log "listCaseDiff" (["Hello"] == ["hello"])
_ = Debug.log "listUnicode" (["\u{03BB}", "\u{20AC}", "x"] == ["\u{03BB}", "\u{20AC}", "x"])
in
text "done"

Lean translation

This program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm?: the program it is, its modules in the reduced syntax of Chapter 7 with every integer constant at Int or Float by number specialisation, and its CHECK lines as written (g_elm_core_ContainerEqualityStringTest, in StandardElmMech/Generated/ElmCore_CompareI.lean). Lean's evaluator runs the program by the rules of Chapters 7 and 9, and its checks become one generated theorem: some derivation of the program has a log that meets every check, or, for a test that stops at Debug.todo, the program has no meaning.

/-- tests/elm-core/src/ContainerEqualityStringTest.elm -/
def g_elm_core_ContainerEqualityStringTest : Program := {
  name := "ContainerEqualityStringTest", source := "tests/elm-core/src",
  exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
  types := [],
  aliases := [],
  defs := [
    .fn "main" [] (letDefs [.fn "emptyStrings" [] (listE []), .pat pw (ap (qv "Debug" "log") [str "pairEqual", .atexp (.paren (bin "==" (tup2 (str "apple") (str "banana")) (tup2 (str "apple") (str "banana"))))]), .pat pw (ap (qv "Debug" "log") [str "pairFirstDiff", .atexp (.paren (bin "==" (tup2 (str "apple") (str "banana")) (tup2 (str "cherry") (str "banana"))))]), .pat pw (ap (qv "Debug" "log") [str "pairSecondDiff", .atexp (.paren (bin "==" (tup2 (str "apple") (str "banana")) (tup2 (str "apple") (str "cherry"))))]), .pat pw (ap (qv "Debug" "log") [str "pairEmpty", .atexp (.paren (bin "==" (tup2 (str "") (str "")) (tup2 (str "") (str ""))))]), .pat pw (ap (qv "Debug" "log") [str "pairCaseDiff", .atexp (.paren (bin "==" (tup2 (str "Apple") (str "banana")) (tup2 (str "apple") (str "banana"))))]), .pat pw (ap (qv "Debug" "log") [str "pairPrefixDiff", .atexp (.paren (bin "==" (tup2 (str "app") (str "x")) (tup2 (str "apple") (str "x"))))]), .pat pw (ap (qv "Debug" "log") [str "pairUnicode", .atexp (.paren (bin "==" (tup2 (str "λx") (str "€y")) (tup2 (str "λx") (str "€y"))))]), .pat pw (ap (qv "Debug" "log") [str "tripleEqual", .atexp (.paren (bin "==" (tup3 (str "a") (str "b") (str "c")) (tup3 (str "a") (str "b") (str "c"))))]), .pat pw (ap (qv "Debug" "log") [str "tripleMidDiff", .atexp (.paren (bin "==" (tup3 (str "a") (str "b") (str "c")) (tup3 (str "a") (str "x") (str "c"))))]), .pat pw (ap (qv "Debug" "log") [str "tripleWithEmpty", .atexp (.paren (bin "==" (tup3 (str "") (str "b") (str "")) (tup3 (str "") (str "b") (str ""))))]), .pat pw (ap (qv "Debug" "log") [str "tripleUnicode", .atexp (.paren (bin "==" (tup3 (str "α") (str "β") (str "γ")) (tup3 (str "α") (str "β") (str "γ"))))]), .pat pw (ap (qv "Debug" "log") [str "listEqual", .atexp (.paren (bin "==" (listE [str "a", str "b", str "c"]) (listE [str "a", str "b", str "c"])))]), .pat pw (ap (qv "Debug" "log") [str "listLenDiff", .atexp (.paren (bin "==" (listE [str "a", str "b"]) (listE [str "a", str "b", str "c"])))]), .pat pw (ap (qv "Debug" "log") [str "listEmpty", .atexp (.paren (bin "==" (v "emptyStrings") (listE [])))]), .pat pw (ap (qv "Debug" "log") [str "listEmptyStrings", .atexp (.paren (bin "==" (listE [str "", str "", str ""]) (listE [str "", str "", str ""])))]), .pat pw (ap (qv "Debug" "log") [str "listCaseDiff", .atexp (.paren (bin "==" (listE [str "Hello"]) (listE [str "hello"])))]), .pat pw (ap (qv "Debug" "log") [str "listUnicode", .atexp (.paren (bin "==" (listE [str "λ", str "€", str "x"]) (listE [str "λ", str "€", str "x"])))])] (ap (v "text") [str "done"])) ],
  checks := [
    chk .check "pairEqual: True" .data,
    chk .check "pairFirstDiff: False" .data,
    chk .check "pairSecondDiff: False" .data,
    chk .check "pairEmpty: True" .data,
    chk .check "pairCaseDiff: False" .data,
    chk .check "pairPrefixDiff: False" .data,
    chk .check "pairUnicode: True" .data,
    chk .check "tripleEqual: True" .data,
    chk .check "tripleMidDiff: False" .data,
    chk .check "tripleWithEmpty: True" .data,
    chk .check "tripleUnicode: True" .data,
    chk .check "listEqual: True" .data,
    chk .check "listLenDiff: False" .data,
    chk .check "listEmpty: True" .data,
    chk .check "listEmptyStrings: True" .data,
    chk .check "listCaseDiff: False" .data,
    chk .check "listUnicode: True" .data ] }

Reading the translation: v "x" is the variable x, c "K" the constructor K, i 42 the integer 42 at Int, .scon (.intF 2) the integer 2 at Float, and str "s" a string; ap f [a, b] applies f to a and then b, and bin "+" a b is a + b. lams, caseOf, ifte, listE, tup2 and recE build lambdas, case, if, lists, pairs and records by the book's derived forms; pv, pw and pcon are variable, wildcard and constructor patterns. defs are the program's top-level definitions and locals the other declarations of main's let, placed in a let around each check; ckk label value kind exp is one check. A name with $ (incF$Float) is a copy number specialisation made.

Static semantics (Chapters 4, 5 and 9): legal_elm_core_ContainerEqualityStringTest states that the program as written is legal, with no hypothesis: the proved inference W gives each module a principal derivation, which meets the syntactic restrictions and the further restrictions, with a type of main Chapter 9 allows. End to end: spec_elm_core_ContainerEqualityStringTest states that Lean computes the reduced program above from the source (derived forms, inference, the proved checker, number specialisation, type erasure), so the theorems about it do not trust the translator's elaboration ([elab]); mean_elm_core_ContainerEqualityStringTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_ContainerEqualityStringTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.