ArrayEqualityFlagsTest
Tags:elm-spec
Checks, in A Standard Definition of Elm?:basis Basics.eqbasis Basics.neqbasis Array.Arrayfigure dynamic-basis-eq
Translated into Lean for the mechanisation of the book: see its Lean translation.
Two arrays are equal under `==` when they hold equal elements in the same order: arrays received as flags are compared, with the same elements, a different element, and a different length. A Standard Definition of Elm? gives arrays as the lists of their elements (Appendix D, Arrays), compared by the fourth clause of the equality of values: equal exactly when their lists are. An array reaches a program within the definition only through its flags or a port, so the four arrays are the flags, a JSON object decoded at a record of `Array Int` fields. `ArrayAppendCanonicalTest` and `ArrayEqAfterPushTest` compare arrays built by elm/core's library functions.
Results
elm-0.19.1
passran in 58 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. same: True differentElement: False differentLength: False notEqualSame: False
elm-0.19.2
passran in 47 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. same: True differentElement: False differentLength: False notEqualSame: False
elm-0.19.3
passran in 62 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. same: True differentElement: False differentLength: False notEqualSame: False
lamdera-1.5.0
passran in 48 msOutput
same: True differentElement: False differentLength: False notEqualSame: False
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/ArrayEqualityFlagsTest] in its title.
Source
The -- CHECK: lines give the expected output.
module ArrayEqualityFlagsTest exposing (main)
{-| Two arrays are equal under `==` when they hold equal elements in the same order: arrays
received as flags are compared, with the same elements, a different element, and a different
length.
A Standard Definition of Elm? gives arrays as the lists of their elements (Appendix D, Arrays),
compared by the fourth clause of the equality of values: equal exactly when their lists are. An
array reaches a program within the definition only through its flags or a port, so the four
arrays are the flags, a JSON object decoded at a record of `Array Int` fields.
`ArrayAppendCanonicalTest` and `ArrayEqAfterPushTest` compare arrays built by elm/core's library
functions.
-}
-- TAGS: elm-spec, b:Basics.eq, b:Basics.neq, b:Array.Array, fig:dynamic-basis-eq
-- FLAGS: {"a":[1,2,3],"b":[1,2,3],"c":[1,2,4],"d":[1,2]}
-- CHECK: same: True
-- CHECK: differentElement: False
-- CHECK: differentLength: False
-- CHECK: notEqualSame: False
import Array exposing (Array)
import Platform
type alias Flags =
{ a : Array Int
, b : Array Int
, c : Array Int
, d : Array Int
}
init : Flags -> ( (), Cmd msg )
init flags =
let
_ =
Debug.log "same" (flags.a == flags.b)
_ =
Debug.log "differentElement" (flags.a == flags.c)
_ =
Debug.log "differentLength" (flags.a == flags.d)
_ =
Debug.log "notEqualSame" (flags.a /= flags.b)
in
( (), Cmd.none )
main : Program Flags () msg
main =
Platform.worker
{ init = init
, update = \_ model -> ( model, Cmd.none )
, subscriptions = \_ -> Sub.none
}
Lean translation
This worker program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm? (g_elm_ArrayEqualityFlagsTest, in StandardElmMech/Generated/Worker01.lean). Lean evaluates its modules by the rules of Chapter 7, starts it by r:p-init with the flags {"a":[1,2,3],"b":[1,2,3],"c":[1,2,4],"d":[1,2]}, and runs it by the transitions of Chapter 9 under a host that sends nothing. Its checks become one generated theorem: some execution the book allows, under that host, has a log (the modules', then the start's, then each step's) that meets every check. The theorem trusts the parser and the translator's elaboration ([parse] [elab]), the test basis ([harness]) and the parameters of the basis ([params]), and is proved by the kernel.
| Check | Expected (CHECK) | Lean evaluator | Proved by |
|---|---|---|---|
same | True | True | t_elm_ArrayEqualityFlagsTest |
differentElement | False | False | t_elm_ArrayEqualityFlagsTest |
differentLength | False | False | t_elm_ArrayEqualityFlagsTest |
notEqualSame | False | False | t_elm_ArrayEqualityFlagsTest |
/-- tests/elm/src/ArrayEqualityFlagsTest.elm -/
def g_elm_ArrayEqualityFlagsTest : Program := {
name := "ArrayEqualityFlagsTest", source := "tests/elm/src",
exposing := (.items [.var "main"]), imports := [⟨"Array", "Array", some (.items [.tycon "Array"])⟩, ⟨"Platform", "Platform", none⟩],
types := [],
aliases := [("Flags", some ["a", "b", "c", "d"])],
defs := [
.fn "init" [pv "flags"] (letDefs [.pat pw (ap (qv "Debug" "log") [str "same", .atexp (.paren (bin "==" (.atexp (access (A (v "flags")) "a")) (.atexp (access (A (v "flags")) "b"))))]), .pat pw (ap (qv "Debug" "log") [str "differentElement", .atexp (.paren (bin "==" (.atexp (access (A (v "flags")) "a")) (.atexp (access (A (v "flags")) "c"))))]), .pat pw (ap (qv "Debug" "log") [str "differentLength", .atexp (.paren (bin "==" (.atexp (access (A (v "flags")) "a")) (.atexp (access (A (v "flags")) "d"))))]), .pat pw (ap (qv "Debug" "log") [str "notEqualSame", .atexp (.paren (bin "/=" (.atexp (access (A (v "flags")) "a")) (.atexp (access (A (v "flags")) "b"))))])] (tup2 (.atexp .unit) (qv "Cmd" "none"))),
.fn "main" [] (ap (qv "Platform" "worker") [recE [("init", v "init"), ("update", lams [pw, pv "model"] (tup2 (v "model") (qv "Cmd" "none"))), ("subscriptions", lams [pw] (qv "Sub" "none"))]]) ],
checks := [
chk .check "same: True" .data,
chk .check "differentElement: False" .data,
chk .check "differentLength: False" .data,
chk .check "notEqualSame: False" .data ] }
/-- The worker test of ArrayEqualityFlagsTest. -/
def w_elm_ArrayEqualityFlagsTest : Prog.WorkerTest := {
prog := g_elm_ArrayEqualityFlagsTest,
flagsType := (.record (.cons "a" (.array .int) (.cons "b" (.array .int) (.cons "c" (.array .int) (.cons "d" (.array .int) .nil))))),
flags := (Eff.BVal.mkObj [("a", (Eff.BVal.array [(.num (Eff.jnum (1) (0))), (.num (Eff.jnum (2) (0))), (.num (Eff.jnum (3) (0)))])), ("b", (Eff.BVal.array [(.num (Eff.jnum (1) (0))), (.num (Eff.jnum (2) (0))), (.num (Eff.jnum (3) (0)))])), ("c", (Eff.BVal.array [(.num (Eff.jnum (1) (0))), (.num (Eff.jnum (2) (0))), (.num (Eff.jnum (4) (0)))])), ("d", (Eff.BVal.array [(.num (Eff.jnum (1) (0))), (.num (Eff.jnum (2) (0)))]))]),
host := .none,
checks := [] }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_ArrayEqualityFlagsTest 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_ArrayEqualityFlagsTest 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_ArrayEqualityFlagsTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_ArrayEqualityFlagsTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.