Elm Exactly
Results / elm-core /

ContainerEqualityIntTest

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 `Int`.

  - Pairs: equal, differing in either position, negative numbers, differing
    only in sign, and zeros.
  - Triples: equal, differing in the middle, mixed signs, and the 32-bit
    minimum and maximum values `-2147483648` and `2147483647`.
  - Lists: equal, the shorter list on either side, two empty lists, negative
    numbers, and mixed signs.

The number literals are not annotated, so where nothing else fixes their type A Standard
Definition of Elm? takes them to be Float (ruling A27); Floats with these integral values order and
compare as the Ints would, so the results are the same.

Results

elm-0.19.1

passran in 58 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
pairNegatives: True
pairSignDiff: False
pairZero: True
tripleEqual: True
tripleMidDiff: False
tripleSignMix: True
tripleMinMax: True
listEqual: True
listLenDiff: False
listPrefixExtra: False
listEmpty: True
listNegatives: True
listSignMix: True

elm-0.19.2

passran in 70 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
pairNegatives: True
pairSignDiff: False
pairZero: True
tripleEqual: True
tripleMidDiff: False
tripleSignMix: True
tripleMinMax: True
listEqual: True
listLenDiff: False
listPrefixExtra: False
listEmpty: True
listNegatives: True
listSignMix: True

elm-0.19.3

passran in 44 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
pairNegatives: True
pairSignDiff: False
pairZero: True
tripleEqual: True
tripleMidDiff: False
tripleSignMix: True
tripleMinMax: True
listEqual: True
listLenDiff: False
listPrefixExtra: False
listEmpty: True
listNegatives: True
listSignMix: True

lamdera-1.5.0

passran in 77 ms
Output
pairEqual: True
pairFirstDiff: False
pairSecondDiff: False
pairNegatives: True
pairSignDiff: False
pairZero: True
tripleEqual: True
tripleMidDiff: False
tripleSignMix: True
tripleMinMax: True
listEqual: True
listLenDiff: False
listPrefixExtra: False
listEmpty: True
listNegatives: True
listSignMix: True

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module ContainerEqualityIntTest exposing (main)
{-| Checks `==` on pairs, triples and lists of `Int`.
- Pairs: equal, differing in either position, negative numbers, differing
only in sign, and zeros.
- Triples: equal, differing in the middle, mixed signs, and the 32-bit
minimum and maximum values `-2147483648` and `2147483647`.
- Lists: equal, the shorter list on either side, two empty lists, negative
numbers, and mixed signs.
The number literals are not annotated, so where nothing else fixes their type A Standard
Definition of Elm? takes them to be Float (ruling A27); Floats with these integral values order and
compare as the Ints would, so the results are the same.
-}
-- TAGS: elm-spec, b:Basics.eq
-- CHECK: pairEqual: True
-- CHECK: pairFirstDiff: False
-- CHECK: pairSecondDiff: False
-- CHECK: pairNegatives: True
-- CHECK: pairSignDiff: False
-- CHECK: pairZero: True
-- CHECK: tripleEqual: True
-- CHECK: tripleMidDiff: False
-- CHECK: tripleSignMix: True
-- CHECK: tripleMinMax: True
-- CHECK: listEqual: True
-- CHECK: listLenDiff: False
-- CHECK: listPrefixExtra: False
-- CHECK: listEmpty: True
-- CHECK: listNegatives: True
-- CHECK: listSignMix: True
import Html exposing (text)
main =
let
emptyInts : List Int
emptyInts = []
-- Tuple2 ---------------------------------------------------------
_ = Debug.log "pairEqual" ((1, 2) == (1, 2))
_ = Debug.log "pairFirstDiff" ((1, 2) == (3, 2))
_ = Debug.log "pairSecondDiff" ((1, 2) == (1, 3))
_ = Debug.log "pairNegatives" ((-7, -8) == (-7, -8))
_ = Debug.log "pairSignDiff" ((-1, 2) == (1, 2))
_ = Debug.log "pairZero" ((0, 0) == (0, 0))
-- Tuple3 ---------------------------------------------------------
_ = Debug.log "tripleEqual" ((1, 2, 3) == (1, 2, 3))
_ = Debug.log "tripleMidDiff" ((1, 2, 3) == (1, 9, 3))
_ = Debug.log "tripleSignMix" ((-1, 0, 1) == (-1, 0, 1))
_ = Debug.log "tripleMinMax" ((-2147483648, 0, 2147483647) == (-2147483648, 0, 2147483647))
-- List -----------------------------------------------------------
_ = Debug.log "listEqual" ([1, 2, 3] == [1, 2, 3])
_ = Debug.log "listLenDiff" ([1, 2] == [1, 2, 3])
_ = Debug.log "listPrefixExtra" ([1, 2, 3] == [1, 2])
_ = Debug.log "listEmpty" (emptyInts == [])
_ = Debug.log "listNegatives" ([-3, -2, -1] == [-3, -2, -1])
_ = Debug.log "listSignMix" ([-1, 0, 1] == [-1, 0, 1])
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_ContainerEqualityIntTest, 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/ContainerEqualityIntTest.elm -/
def g_elm_core_ContainerEqualityIntTest : Program := {
  name := "ContainerEqualityIntTest", source := "tests/elm-core/src",
  exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
  types := [],
  aliases := [],
  defs := [
    .fn "main" [] (letDefs [.fn "emptyInts" [] (listE []), .pat pw (ap (qv "Debug" "log") [str "pairEqual", .atexp (.paren (bin "==" (tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2)))) (tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))))))]), .pat pw (ap (qv "Debug" "log") [str "pairFirstDiff", .atexp (.paren (bin "==" (tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2)))) (tup2 (.atexp (.scon (.intF 3))) (.atexp (.scon (.intF 2))))))]), .pat pw (ap (qv "Debug" "log") [str "pairSecondDiff", .atexp (.paren (bin "==" (tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2)))) (tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 3))))))]), .pat pw (ap (qv "Debug" "log") [str "pairNegatives", .atexp (.paren (bin "==" (tup2 (.atexp (neg (.scon (.intF 7)))) (.atexp (neg (.scon (.intF 8))))) (tup2 (.atexp (neg (.scon (.intF 7)))) (.atexp (neg (.scon (.intF 8)))))))]), .pat pw (ap (qv "Debug" "log") [str "pairSignDiff", .atexp (.paren (bin "==" (tup2 (.atexp (neg (.scon (.intF 1)))) (.atexp (.scon (.intF 2)))) (tup2 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))))))]), .pat pw (ap (qv "Debug" "log") [str "pairZero", .atexp (.paren (bin "==" (tup2 (.atexp (.scon (.intF 0))) (.atexp (.scon (.intF 0)))) (tup2 (.atexp (.scon (.intF 0))) (.atexp (.scon (.intF 0))))))]), .pat pw (ap (qv "Debug" "log") [str "tripleEqual", .atexp (.paren (bin "==" (tup3 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))) (.atexp (.scon (.intF 3)))) (tup3 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))) (.atexp (.scon (.intF 3))))))]), .pat pw (ap (qv "Debug" "log") [str "tripleMidDiff", .atexp (.paren (bin "==" (tup3 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2))) (.atexp (.scon (.intF 3)))) (tup3 (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 9))) (.atexp (.scon (.intF 3))))))]), .pat pw (ap (qv "Debug" "log") [str "tripleSignMix", .atexp (.paren (bin "==" (tup3 (.atexp (neg (.scon (.intF 1)))) (.atexp (.scon (.intF 0))) (.atexp (.scon (.intF 1)))) (tup3 (.atexp (neg (.scon (.intF 1)))) (.atexp (.scon (.intF 0))) (.atexp (.scon (.intF 1))))))]), .pat pw (ap (qv "Debug" "log") [str "tripleMinMax", .atexp (.paren (bin "==" (tup3 (.atexp (neg (.scon (.intF 2147483648)))) (.atexp (.scon (.intF 0))) (.atexp (.scon (.intF 2147483647)))) (tup3 (.atexp (neg (.scon (.intF 2147483648)))) (.atexp (.scon (.intF 0))) (.atexp (.scon (.intF 2147483647))))))]), .pat pw (ap (qv "Debug" "log") [str "listEqual", .atexp (.paren (bin "==" (listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2)), .atexp (.scon (.intF 3))]) (listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2)), .atexp (.scon (.intF 3))])))]), .pat pw (ap (qv "Debug" "log") [str "listLenDiff", .atexp (.paren (bin "==" (listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2))]) (listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2)), .atexp (.scon (.intF 3))])))]), .pat pw (ap (qv "Debug" "log") [str "listPrefixExtra", .atexp (.paren (bin "==" (listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2)), .atexp (.scon (.intF 3))]) (listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2))])))]), .pat pw (ap (qv "Debug" "log") [str "listEmpty", .atexp (.paren (bin "==" (v "emptyInts") (listE [])))]), .pat pw (ap (qv "Debug" "log") [str "listNegatives", .atexp (.paren (bin "==" (listE [.atexp (neg (.scon (.intF 3))), .atexp (neg (.scon (.intF 2))), .atexp (neg (.scon (.intF 1)))]) (listE [.atexp (neg (.scon (.intF 3))), .atexp (neg (.scon (.intF 2))), .atexp (neg (.scon (.intF 1)))])))]), .pat pw (ap (qv "Debug" "log") [str "listSignMix", .atexp (.paren (bin "==" (listE [.atexp (neg (.scon (.intF 1))), .atexp (.scon (.intF 0)), .atexp (.scon (.intF 1))]) (listE [.atexp (neg (.scon (.intF 1))), .atexp (.scon (.intF 0)), .atexp (.scon (.intF 1))])))])] (ap (v "text") [str "done"])) ],
  checks := [
    chk .check "pairEqual: True" .data,
    chk .check "pairFirstDiff: False" .data,
    chk .check "pairSecondDiff: False" .data,
    chk .check "pairNegatives: True" .data,
    chk .check "pairSignDiff: False" .data,
    chk .check "pairZero: True" .data,
    chk .check "tripleEqual: True" .data,
    chk .check "tripleMidDiff: False" .data,
    chk .check "tripleSignMix: True" .data,
    chk .check "tripleMinMax: True" .data,
    chk .check "listEqual: True" .data,
    chk .check "listLenDiff: False" .data,
    chk .check "listPrefixExtra: False" .data,
    chk .check "listEmpty: True" .data,
    chk .check "listNegatives: True" .data,
    chk .check "listSignMix: 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_ContainerEqualityIntTest 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_ContainerEqualityIntTest 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_ContainerEqualityIntTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_ContainerEqualityIntTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.