Elm Exactly
Results / elm-core /

EqualityBoolRecordTest

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
Record equality compares `Bool` fields correctly.

The record `ref` is `{ a = True, b = False }`. It equals a separately written
record with the same fields, and differs from records that flip `a`, flip `b` or
flip both. `recFF_FF` compares a record with both fields `False` against a
literal with the same fields, which is `True`.

Results

elm-0.19.1

passran in 83 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
recEq: True
recDiffA: False
recDiffB: False
recDiffBoth: False
recFF_FF: True

elm-0.19.2

passran in 64 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
recEq: True
recDiffA: False
recDiffB: False
recDiffBoth: False
recFF_FF: True

elm-0.19.3

passran in 50 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
recEq: True
recDiffA: False
recDiffB: False
recDiffBoth: False
recFF_FF: True

lamdera-1.5.0

passran in 78 ms
Output
recEq: True
recDiffA: False
recDiffB: False
recDiffBoth: False
recFF_FF: True

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module EqualityBoolRecordTest exposing (main)
{-| Record equality compares `Bool` fields correctly.
The record `ref` is `{ a = True, b = False }`. It equals a separately written
record with the same fields, and differs from records that flip `a`, flip `b` or
flip both. `recFF_FF` compares a record with both fields `False` against a
literal with the same fields, which is `True`.
-}
-- TAGS: elm-spec, b:Basics.eq
-- CHECK: recEq: True
-- CHECK: recDiffA: False
-- CHECK: recDiffB: False
-- CHECK: recDiffBoth: False
-- CHECK: recFF_FF: True
import Html exposing (text)
type alias Pair =
{ a : Bool, b : Bool }
main =
let
ref : Pair
ref = { a = True, b = False }
sameAsRef : Pair
sameAsRef = { a = True, b = False }
flipA : Pair
flipA = { a = False, b = False }
flipB : Pair
flipB = { a = True, b = True }
flipBoth : Pair
flipBoth = { a = False, b = True }
bothFalse : Pair
bothFalse = { a = False, b = False }
_ = Debug.log "recEq" (ref == sameAsRef)
_ = Debug.log "recDiffA" (ref == flipA)
_ = Debug.log "recDiffB" (ref == flipB)
_ = Debug.log "recDiffBoth" (ref == flipBoth)
_ = Debug.log "recFF_FF" (bothFalse == { a = False, b = False })
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_EqualityBoolRecordTest, in StandardElmMech/Generated/ElmCore_CoreIssue115.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.

CheckExpected (CHECK)Lean evaluatorProved by
recEqTrueTruet_elm_core_EqualityBoolRecordTest
recDiffAFalseFalset_elm_core_EqualityBoolRecordTest
recDiffBFalseFalset_elm_core_EqualityBoolRecordTest
recDiffBothFalseFalset_elm_core_EqualityBoolRecordTest
recFF_FFTrueTruet_elm_core_EqualityBoolRecordTest
/-- tests/elm-core/src/EqualityBoolRecordTest.elm -/
def g_elm_core_EqualityBoolRecordTest : Program := {
  name := "EqualityBoolRecordTest", source := "tests/elm-core/src",
  exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
  types := [],
  aliases := [("Pair", some ["a", "b"])],
  defs := [
    .fn "main" [] (letDefs [.fn "ref" [] (recE [("a", c "True"), ("b", c "False")]), .fn "sameAsRef" [] (recE [("a", c "True"), ("b", c "False")]), .fn "flipA" [] (recE [("a", c "False"), ("b", c "False")]), .fn "flipB" [] (recE [("a", c "True"), ("b", c "True")]), .fn "flipBoth" [] (recE [("a", c "False"), ("b", c "True")]), .fn "bothFalse" [] (recE [("a", c "False"), ("b", c "False")]), .pat pw (ap (qv "Debug" "log") [str "recEq", .atexp (.paren (bin "==" (v "ref") (v "sameAsRef")))]), .pat pw (ap (qv "Debug" "log") [str "recDiffA", .atexp (.paren (bin "==" (v "ref") (v "flipA")))]), .pat pw (ap (qv "Debug" "log") [str "recDiffB", .atexp (.paren (bin "==" (v "ref") (v "flipB")))]), .pat pw (ap (qv "Debug" "log") [str "recDiffBoth", .atexp (.paren (bin "==" (v "ref") (v "flipBoth")))]), .pat pw (ap (qv "Debug" "log") [str "recFF_FF", .atexp (.paren (bin "==" (v "bothFalse") (recE [("a", c "False"), ("b", c "False")])))])] (ap (v "text") [str "done"])) ],
  checks := [
    chk .check "recEq: True" .data,
    chk .check "recDiffA: False" .data,
    chk .check "recDiffB: False" .data,
    chk .check "recDiffBoth: False" .data,
    chk .check "recFF_FF: 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_EqualityBoolRecordTest 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_EqualityBoolRecordTest 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_EqualityBoolRecordTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_EqualityBoolRecordTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.