Elm Exactly
Results / elm /

WideCtorField24Test

Tags:elm-spec

Checks, in A Standard Definition of Elm?:rule sm-conbindrule dm-conbindrule d-app-conrule d-pat-con

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
A custom type constructor with 27 fields, 25 `Int`s followed by a `Float` and
a `Char`, keeps every field, and pattern matching reads back the later ones.

`make 1000` builds `Wide 1000 1001 ... 1024 2.5 'z'`. The test reads fields 23
to 26 and adds field 24 of two separately built values (2048).

Results

elm-0.19.1

passran in 48 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
field23: 1023
field24: 1024
field25: 2.5
field26: 'z'
sum24: 2048

elm-0.19.2

passran in 63 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
field23: 1023
field24: 1024
field25: 2.5
field26: 'z'
sum24: 2048

elm-0.19.3

passran in 57 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
sum24: 2048
field26: 'z'
field25: 2.5
field24: 1024
field23: 1023

lamdera-1.5.0

passran in 61 ms
Output
sum24: 2048
field26: 'z'
field25: 2.5
field24: 1024
field23: 1023

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module WideCtorField24Test exposing (main)
{-| A custom type constructor with 27 fields, 25 `Int`s followed by a `Float` and
a `Char`, keeps every field, and pattern matching reads back the later ones.
`make 1000` builds `Wide 1000 1001 ... 1024 2.5 'z'`. The test reads fields 23
to 26 and adds field 24 of two separately built values (2048).
-}
-- TAGS: elm-spec, sm-conbind, dm-conbind, d-app-con, d-pat-con
-- CHECK: field23: 1023
-- CHECK: field24: 1024
-- CHECK: field25: 2.5
-- CHECK: field26: 'z'
-- CHECK: sum24: 2048
import Html exposing (text)
type Wide
= Wide Int Int Int Int Int Int Int Int Int Int Int Int Int Int Int Int Int Int Int Int Int Int Int Int Int Float Char
make : Int -> Wide
make base =
Wide (base + 0) (base + 1) (base + 2) (base + 3) (base + 4) (base + 5) (base + 6) (base + 7) (base + 8) (base + 9) (base + 10) (base + 11) (base + 12) (base + 13) (base + 14) (base + 15) (base + 16) (base + 17) (base + 18) (base + 19) (base + 20) (base + 21) (base + 22) (base + 23) (base + 24) 2.5 'z'
field23 : Wide -> Int
field23 w =
case w of
Wide f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 f25 f26 ->
f23
field24 : Wide -> Int
field24 w =
case w of
Wide f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 f25 f26 ->
f24
field25 : Wide -> Float
field25 w =
case w of
Wide f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 f25 f26 ->
f25
field26 : Wide -> Char
field26 w =
case w of
Wide f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f20 f21 f22 f23 f24 f25 f26 ->
f26
main =
let
base =
1000 + (Char.toCode 'b' - Char.toCode 'a') - 1
w =
make base
_ =
Debug.log "field23" (field23 w)
_ =
Debug.log "field24" (field24 w)
_ =
Debug.log "field25" (field25 w)
_ =
Debug.log "field26" (field26 w)
_ =
Debug.log "sum24" (field24 w + field24 (make base))
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_WideCtorField24Test, in StandardElmMech/Generated/Elm_TailRecT.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
field2310231023t_elm_WideCtorField24Test
field2410241024t_elm_WideCtorField24Test
field252.52.5t_elm_WideCtorField24Test
field26'z''z't_elm_WideCtorField24Test
sum2420482048t_elm_WideCtorField24Test
/-- tests/elm/src/WideCtorField24Test.elm -/
def g_elm_WideCtorField24Test : Program := {
  name := "WideCtorField24Test", source := "tests/elm/src",
  exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
  types := [("Wide", [("Wide", 27)])],
  aliases := [],
  defs := [
    .fn "make" [pv "base"] (ap (c "Wide") [.atexp (.paren (bin "+" (v "base") (i 0))), .atexp (.paren (bin "+" (v "base") (i 1))), .atexp (.paren (bin "+" (v "base") (i 2))), .atexp (.paren (bin "+" (v "base") (i 3))), .atexp (.paren (bin "+" (v "base") (i 4))), .atexp (.paren (bin "+" (v "base") (i 5))), .atexp (.paren (bin "+" (v "base") (i 6))), .atexp (.paren (bin "+" (v "base") (i 7))), .atexp (.paren (bin "+" (v "base") (i 8))), .atexp (.paren (bin "+" (v "base") (i 9))), .atexp (.paren (bin "+" (v "base") (i 10))), .atexp (.paren (bin "+" (v "base") (i 11))), .atexp (.paren (bin "+" (v "base") (i 12))), .atexp (.paren (bin "+" (v "base") (i 13))), .atexp (.paren (bin "+" (v "base") (i 14))), .atexp (.paren (bin "+" (v "base") (i 15))), .atexp (.paren (bin "+" (v "base") (i 16))), .atexp (.paren (bin "+" (v "base") (i 17))), .atexp (.paren (bin "+" (v "base") (i 18))), .atexp (.paren (bin "+" (v "base") (i 19))), .atexp (.paren (bin "+" (v "base") (i 20))), .atexp (.paren (bin "+" (v "base") (i 21))), .atexp (.paren (bin "+" (v "base") (i 22))), .atexp (.paren (bin "+" (v "base") (i 23))), .atexp (.paren (bin "+" (v "base") (i 24))), .atexp (.scon (.float 25 (-1))), .atexp (chA 'z')]),
    .fn "field23" [pv "w"] (caseOf (v "w") [(pcon "Wide" [pv "f0", pv "f1", pv "f2", pv "f3", pv "f4", pv "f5", pv "f6", pv "f7", pv "f8", pv "f9", pv "f10", pv "f11", pv "f12", pv "f13", pv "f14", pv "f15", pv "f16", pv "f17", pv "f18", pv "f19", pv "f20", pv "f21", pv "f22", pv "f23", pv "f24", pv "f25", pv "f26"], v "f23")]),
    .fn "field24" [pv "w"] (caseOf (v "w") [(pcon "Wide" [pv "f0", pv "f1", pv "f2", pv "f3", pv "f4", pv "f5", pv "f6", pv "f7", pv "f8", pv "f9", pv "f10", pv "f11", pv "f12", pv "f13", pv "f14", pv "f15", pv "f16", pv "f17", pv "f18", pv "f19", pv "f20", pv "f21", pv "f22", pv "f23", pv "f24", pv "f25", pv "f26"], v "f24")]),
    .fn "field25" [pv "w"] (caseOf (v "w") [(pcon "Wide" [pv "f0", pv "f1", pv "f2", pv "f3", pv "f4", pv "f5", pv "f6", pv "f7", pv "f8", pv "f9", pv "f10", pv "f11", pv "f12", pv "f13", pv "f14", pv "f15", pv "f16", pv "f17", pv "f18", pv "f19", pv "f20", pv "f21", pv "f22", pv "f23", pv "f24", pv "f25", pv "f26"], v "f25")]),
    .fn "field26" [pv "w"] (caseOf (v "w") [(pcon "Wide" [pv "f0", pv "f1", pv "f2", pv "f3", pv "f4", pv "f5", pv "f6", pv "f7", pv "f8", pv "f9", pv "f10", pv "f11", pv "f12", pv "f13", pv "f14", pv "f15", pv "f16", pv "f17", pv "f18", pv "f19", pv "f20", pv "f21", pv "f22", pv "f23", pv "f24", pv "f25", pv "f26"], v "f26")]),
    .fn "main" [] (letDefs [.fn "base" [] (bin "-" (bin "+" (i 1000) (.atexp (.paren (bin "-" (ap (qv "Char" "toCode") [.atexp (chA 'b')]) (ap (qv "Char" "toCode") [.atexp (chA 'a')]))))) (i 1)), .fn "w" [] (ap (v "make") [v "base"]), .pat pw (ap (qv "Debug" "log") [str "field23", .atexp (.paren (ap (v "field23") [v "w"]))]), .pat pw (ap (qv "Debug" "log") [str "field24", .atexp (.paren (ap (v "field24") [v "w"]))]), .pat pw (ap (qv "Debug" "log") [str "field25", .atexp (.paren (ap (v "field25") [v "w"]))]), .pat pw (ap (qv "Debug" "log") [str "field26", .atexp (.paren (ap (v "field26") [v "w"]))]), .pat pw (ap (qv "Debug" "log") [str "sum24", .atexp (.paren (bin "+" (ap (v "field24") [v "w"]) (ap (v "field24") [.atexp (.paren (ap (v "make") [v "base"]))])))])] (ap (v "text") [str "done"])) ],
  checks := [
    chk .check "field23: 1023" .int,
    chk .check "field24: 1024" .int,
    chk .check "field25: 2.5" .float,
    chk .check "field26: 'z'" .char,
    chk .check "sum24: 2048" .int ] }

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