Elm Exactly
Results / elm-core /

StandardA51FunctionEqualityTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:rule d-app-basic-apply

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

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail

Issue: elm/compiler#1145

`==` on two functions gives a Bool; the program goes on.

<https://github.com/elm/compiler/issues/1145>

A Standard Definition of Elm?, ruling A51: equality that reaches two functions gives a Bool that
the definition does not specify; no evaluation ends in a run-time error.
<https://elm-test-suite.netlify.app/standard/basis/Basics/eq>

Elm 0.19.1 stops the program: "Trying to use `(==)` on functions."

Results

elm-0.19.1

failran in 55 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA51FunctionEqualityTest.js:753
			throw new Error('Trying to use `(==)` on functions.\nThere is no way to know if functions are "the same" in the Elm sense.\nRead more about this at https://package.elm-lang.org/packages/elm/core/latest/Basics#== which describes why it is this way and what the better version will look like.');
			^

Error: Trying to use `(==)` on functions.
There is no way to know if functions are "the same" in the Elm sense.
Read more about this at https://package.elm-lang.org/packages/elm/core/latest/Basics#== which describes why it is this way and what the better version will look like.
    at _Debug_crash (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA51FunctionEqualityTest.js:753:10)
    at _Utils_eqHelp (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA51FunctionEqualityTest.js:106:30)
    at _Utils_eq (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA51FunctionEqualityTest.js:88:35)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA51FunctionEqualityTest.js:4435:13
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA51FunctionEqualityTest.js:4444:2
    at Object.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.1/elm-core/out/StandardA51FunctionEqualityTest.js:4445:142)
    at Module._compile (node:internal/modules/cjs/loader:1781:14)
    at Object..js (node:internal/modules/cjs/loader:1913:10)
    at Module.load (node:internal/modules/cjs/loader:1505:32)
    at Function._load (node:internal/modules/cjs/loader:1309:12)

Node.js v22.23.5

elm-0.19.2

failran in 48 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA51FunctionEqualityTest.js:753
			throw new Error('Trying to use `(==)` on functions.\nThere is no way to know if functions are "the same" in the Elm sense.\nRead more about this at https://package.elm-lang.org/packages/elm/core/latest/Basics#== which describes why it is this way and what the better version will look like.');
			^

Error: Trying to use `(==)` on functions.
There is no way to know if functions are "the same" in the Elm sense.
Read more about this at https://package.elm-lang.org/packages/elm/core/latest/Basics#== which describes why it is this way and what the better version will look like.
    at _Debug_crash (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA51FunctionEqualityTest.js:753:10)
    at _Utils_eqHelp (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA51FunctionEqualityTest.js:106:30)
    at _Utils_eq (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA51FunctionEqualityTest.js:88:35)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA51FunctionEqualityTest.js:4435:13
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA51FunctionEqualityTest.js:4444:2
    at Object.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.2/elm-core/out/StandardA51FunctionEqualityTest.js:4445:142)
    at Module._compile (node:internal/modules/cjs/loader:1781:14)
    at Object..js (node:internal/modules/cjs/loader:1913:10)
    at Module.load (node:internal/modules/cjs/loader:1505:32)
    at Function._load (node:internal/modules/cjs/loader:1309:12)

Node.js v22.23.5

elm-0.19.3

failran in 45 ms
exit code 1, expected 0
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA51FunctionEqualityTest.js:488
			throw new Error('Trying to use `(==)` on functions.\nThere is no way to know if functions are "the same" in the Elm sense.\nRead more about this at https://package.elm-lang.org/packages/elm/core/latest/Basics#== which describes why it is this way and what the better version will look like.');
			^

Error: Trying to use `(==)` on functions.
There is no way to know if functions are "the same" in the Elm sense.
Read more about this at https://package.elm-lang.org/packages/elm/core/latest/Basics#== which describes why it is this way and what the better version will look like.
    at _Debug_crash (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA51FunctionEqualityTest.js:488:10)
    at _Utils_eqHelp (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA51FunctionEqualityTest.js:554:30)
    at _Utils_eq (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA51FunctionEqualityTest.js:536:35)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA51FunctionEqualityTest.js:4435:13
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA51FunctionEqualityTest.js:4444:2
    at Object.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/elm-0.19.3/elm-core/out/StandardA51FunctionEqualityTest.js:4445:142)
    at Module._compile (node:internal/modules/cjs/loader:1781:14)
    at Object..js (node:internal/modules/cjs/loader:1913:10)
    at Module.load (node:internal/modules/cjs/loader:1505:32)
    at Function._load (node:internal/modules/cjs/loader:1309:12)

Node.js v22.23.5

lamdera-1.5.0

failran in 50 ms
exit code 1, expected 0
--- output ---
/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA51FunctionEqualityTest.js:507
			throw new Error('Trying to use `(==)` on functions.\nThere is no way to know if functions are "the same" in the Elm sense.\nRead more about this at https://package.elm-lang.org/packages/elm/core/latest/Basics#== which describes why it is this way and what the better version will look like.');
			^

Error: Trying to use `(==)` on functions.
There is no way to know if functions are "the same" in the Elm sense.
Read more about this at https://package.elm-lang.org/packages/elm/core/latest/Basics#== which describes why it is this way and what the better version will look like.
    at _Debug_crash (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA51FunctionEqualityTest.js:507:10)
    at _Utils_eqHelp (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA51FunctionEqualityTest.js:573:30)
    at _Utils_eq (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA51FunctionEqualityTest.js:555:35)
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA51FunctionEqualityTest.js:5505:13
    at /home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA51FunctionEqualityTest.js:5514:2
    at Object.<anonymous> (/home/runner/work/elm-test-suite/elm-test-suite/.work/lamdera-1.5.0/elm-core/out/StandardA51FunctionEqualityTest.js:5517:3)
    at Module._compile (node:internal/modules/cjs/loader:1781:14)
    at Object..js (node:internal/modules/cjs/loader:1913:10)
    at Module.load (node:internal/modules/cjs/loader:1505:32)
    at Function._load (node:internal/modules/cjs/loader:1309:12)

Node.js v22.23.5

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module StandardA51FunctionEqualityTest exposing (main)
{-| `==` on two functions gives a Bool; the program goes on.
<https://github.com/elm/compiler/issues/1145>
A Standard Definition of Elm?, ruling A51: equality that reaches two functions gives a Bool that
the definition does not specify; no evaluation ends in a run-time error.
<https://elm-test-suite.netlify.app/standard/basis/Basics/eq>
Elm 0.19.1 stops the program: "Trying to use `(==)` on functions."
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, d-app-basic-apply
-- CHECK: compared: True
import Html
main =
let
-- Two different functions: Elm 0.19.1 first checks whether both operands are one
-- object, so `identity == identity` would not reach the functions.
same =
(\k -> k + 1) == (\k -> k + 2)
_ =
Debug.log "compared" (same || not same)
in
Html.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_StandardA51FunctionEqualityTest, in StandardElmMech/Generated/ElmCore_StandardA42.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
comparedTrueTruet_elm_core_StandardA51FunctionEqualityTest
/-- tests/elm-core/src/StandardA51FunctionEqualityTest.elm -/
def g_elm_core_StandardA51FunctionEqualityTest : Program := {
  name := "StandardA51FunctionEqualityTest", source := "tests/elm-core/src",
  exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", none⟩],
  types := [],
  aliases := [],
  defs := [
    .fn "main" [] (letDefs [.fn "same" [] (bin "==" (.atexp (.paren (lams [pv "k"] (bin "+" (v "k") (.atexp (.scon (.intF 1))))))) (.atexp (.paren (lams [pv "k"] (bin "+" (v "k") (.atexp (.scon (.intF 2)))))))), .pat pw (ap (qv "Debug" "log") [str "compared", .atexp (.paren (orelse (v "same") (ap (v "not") [v "same"])))])] (ap (qv "Html" "text") [str "done"])) ],
  checks := [
    chk .check "compared: 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_StandardA51FunctionEqualityTest 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_StandardA51FunctionEqualityTest 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_StandardA51FunctionEqualityTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_StandardA51FunctionEqualityTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.