Elm Exactly
Results / elm-core /

EqualityBoolIfTest

Tags:elm-spec

Checks, in A Standard Definition of Elm?:basis Basics.eqbasis Basics.neqderived form ifrule d-exp-caserule d-match-firstrule d-match-nextrule d-mrule-matchrule d-mrule-failrule d-pat-atpatrule d-atpat-conrule d-atpat-con-failrule d-atexp-parenderived form infixrule d-atexp-oprule d-exp-apprule d-app-basic-partialrule d-app-basic-apply

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
The result of `==` and `/=` on `Bool` operands drives an `if` expression
correctly.

All four `==` comparisons of `True` and `False` choose `"yes"` exactly when the
operands are equal. The two `/=` cases choose `"yes"` only for `True /= False`.

Results

elm-0.19.1

passran in 85 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
ifTT: "yes"
ifTF: "no"
ifFT: "no"
ifFF: "yes"
nifTT: "no"
nifTF: "yes"

elm-0.19.2

passran in 50 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
ifTT: "yes"
ifTF: "no"
ifFT: "no"
ifFF: "yes"
nifTT: "no"
nifTF: "yes"

elm-0.19.3

passran in 46 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
ifTT: "yes"
ifTF: "no"
ifFT: "no"
ifFF: "yes"
nifTT: "no"
nifTF: "yes"

lamdera-1.5.0

passran in 59 ms
Output
ifTT: "yes"
ifTF: "no"
ifFT: "no"
ifFF: "yes"
nifTT: "no"
nifTF: "yes"

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module EqualityBoolIfTest exposing (main)
{-| The result of `==` and `/=` on `Bool` operands drives an `if` expression
correctly.
All four `==` comparisons of `True` and `False` choose `"yes"` exactly when the
operands are equal. The two `/=` cases choose `"yes"` only for `True /= False`.
-}
-- TAGS: elm-spec, b:Basics.eq, b:Basics.neq, df:if, d-exp-case, d-match-first, d-match-next, d-mrule-match, d-mrule-fail, d-pat-atpat, d-atpat-con, d-atpat-con-fail, d-atexp-paren, df:infix, d-atexp-op, d-exp-app, d-app-basic-partial, d-app-basic-apply
-- CHECK: ifTT: "yes"
-- CHECK: ifTF: "no"
-- CHECK: ifFT: "no"
-- CHECK: ifFF: "yes"
-- CHECK: nifTT: "no"
-- CHECK: nifTF: "yes"
import Html exposing (text)
main =
let
_ = Debug.log "ifTT" (if True == True then "yes" else "no")
_ = Debug.log "ifTF" (if True == False then "yes" else "no")
_ = Debug.log "ifFT" (if False == True then "yes" else "no")
_ = Debug.log "ifFF" (if False == False then "yes" else "no")
_ = Debug.log "nifTT" (if True /= True then "yes" else "no")
_ = Debug.log "nifTF" (if True /= False then "yes" else "no")
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_EqualityBoolIfTest, 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
ifTT"yes""yes"t_elm_core_EqualityBoolIfTest
ifTF"no""no"t_elm_core_EqualityBoolIfTest
ifFT"no""no"t_elm_core_EqualityBoolIfTest
ifFF"yes""yes"t_elm_core_EqualityBoolIfTest
nifTT"no""no"t_elm_core_EqualityBoolIfTest
nifTF"yes""yes"t_elm_core_EqualityBoolIfTest
/-- tests/elm-core/src/EqualityBoolIfTest.elm -/
def g_elm_core_EqualityBoolIfTest : Program := {
  name := "EqualityBoolIfTest", source := "tests/elm-core/src",
  exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
  types := [],
  aliases := [],
  defs := [
    .fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "ifTT", .atexp (.paren (ifte (bin "==" (c "True") (c "True")) (str "yes") (str "no")))]), .pat pw (ap (qv "Debug" "log") [str "ifTF", .atexp (.paren (ifte (bin "==" (c "True") (c "False")) (str "yes") (str "no")))]), .pat pw (ap (qv "Debug" "log") [str "ifFT", .atexp (.paren (ifte (bin "==" (c "False") (c "True")) (str "yes") (str "no")))]), .pat pw (ap (qv "Debug" "log") [str "ifFF", .atexp (.paren (ifte (bin "==" (c "False") (c "False")) (str "yes") (str "no")))]), .pat pw (ap (qv "Debug" "log") [str "nifTT", .atexp (.paren (ifte (bin "/=" (c "True") (c "True")) (str "yes") (str "no")))]), .pat pw (ap (qv "Debug" "log") [str "nifTF", .atexp (.paren (ifte (bin "/=" (c "True") (c "False")) (str "yes") (str "no")))])] (ap (v "text") [str "done"])) ],
  checks := [
    chk .check "ifTT: \"yes\"" .string,
    chk .check "ifTF: \"no\"" .string,
    chk .check "ifFT: \"no\"" .string,
    chk .check "ifFF: \"yes\"" .string,
    chk .check "nifTT: \"no\"" .string,
    chk .check "nifTF: \"yes\"" .string ] }

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_EqualityBoolIfTest 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_EqualityBoolIfTest 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_EqualityBoolIfTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_EqualityBoolIfTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.