WideRecord33Test
Tags:elm-spec
Checks, in A Standard Definition of Elm?:rule d-atexp-recordrule d-exprow-fieldrule d-atpat-recordrule d-patrow-fieldrule d-atexp-update
Translated into Lean for the mechanisation of the book: see its Lean translation.
A record with 33 fields, cycling through `Int`, `Float`, `Char`, `String` and
`Bool`, supports field access, record patterns, update, equality and printing.
The test checks:
- Access to fields 0, 31 and 32.
- A record pattern reading the first and last fields.
- An update that sets the last field to `'!'`.
- `==` against a record built from the same input (`True`) and against the
updated record (`False`).
- `Debug.log` printing all 33 fields.Results
elm-0.19.1
passran in 72 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
f0000: 1000
f0031: 31.5
f0032: 'g'
pattern: (1000,'g')
update: '!'
eq self: True
eq updated: False
show: { f0000 = 1000, f0001 = 1.5, f0002 = 'c', f0003 = "3s", f0004 = True, f0005 = 1005, f0006 = 6.5, f0007 = 'h', f0008 = "8s", f0009 = False, f0010 = 1010, f0011 = 11.5, f0012 = 'm', f0013 = "13s", f0014 = True, f0015 = 1015, f0016 = 16.5, f0017 = 'r', f0018 = "18s", f0019 = False, f0020 = 1020, f0021 = 21.5, f0022 = 'w', f0023 = "23s", f0024 = True, f0025 = 1025, f0026 = 26.5, f0027 = 'b', f0028 = "28s", f0029 = False, f0030 = 1030, f0031 = 31.5, f0032 = 'g' }
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.
f0000: 1000
f0031: 31.5
f0032: 'g'
pattern: (1000,'g')
update: '!'
eq self: True
eq updated: False
show: { f0000 = 1000, f0001 = 1.5, f0002 = 'c', f0003 = "3s", f0004 = True, f0005 = 1005, f0006 = 6.5, f0007 = 'h', f0008 = "8s", f0009 = False, f0010 = 1010, f0011 = 11.5, f0012 = 'm', f0013 = "13s", f0014 = True, f0015 = 1015, f0016 = 16.5, f0017 = 'r', f0018 = "18s", f0019 = False, f0020 = 1020, f0021 = 21.5, f0022 = 'w', f0023 = "23s", f0024 = True, f0025 = 1025, f0026 = 26.5, f0027 = 'b', f0028 = "28s", f0029 = False, f0030 = 1030, f0031 = 31.5, f0032 = 'g' }
elm-0.19.3
passran in 53 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
show: { f0000 = 1000, f0001 = 1.5, f0002 = 'c', f0003 = "3s", f0004 = True, f0005 = 1005, f0006 = 6.5, f0007 = 'h', f0008 = "8s", f0009 = False, f0010 = 1010, f0011 = 11.5, f0012 = 'm', f0013 = "13s", f0014 = True, f0015 = 1015, f0016 = 16.5, f0017 = 'r', f0018 = "18s", f0019 = False, f0020 = 1020, f0021 = 21.5, f0022 = 'w', f0023 = "23s", f0024 = True, f0025 = 1025, f0026 = 26.5, f0027 = 'b', f0028 = "28s", f0029 = False, f0030 = 1030, f0031 = 31.5, f0032 = 'g' }
eq updated: False
eq self: True
update: '!'
pattern: (1000,'g')
f0032: 'g'
f0031: 31.5
f0000: 1000
lamdera-1.5.0
passran in 65 msOutput
show: { f0000 = 1000, f0001 = 1.5, f0002 = 'c', f0003 = "3s", f0004 = True, f0005 = 1005, f0006 = 6.5, f0007 = 'h', f0008 = "8s", f0009 = False, f0010 = 1010, f0011 = 11.5, f0012 = 'm', f0013 = "13s", f0014 = True, f0015 = 1015, f0016 = 16.5, f0017 = 'r', f0018 = "18s", f0019 = False, f0020 = 1020, f0021 = 21.5, f0022 = 'w', f0023 = "23s", f0024 = True, f0025 = 1025, f0026 = 26.5, f0027 = 'b', f0028 = "28s", f0029 = False, f0030 = 1030, f0031 = 31.5, f0032 = 'g' }
eq updated: False
eq self: True
update: '!'
pattern: (1000,'g')
f0032: 'g'
f0031: 31.5
f0000: 1000
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/WideRecord33Test] in its title.
Source
The -- CHECK: lines give the expected output.
module WideRecord33Test exposing (main)
{-| A record with 33 fields, cycling through `Int`, `Float`, `Char`, `String` and
`Bool`, supports field access, record patterns, update, equality and printing.
The test checks:
- Access to fields 0, 31 and 32.
- A record pattern reading the first and last fields.
- An update that sets the last field to `'!'`.
- `==` against a record built from the same input (`True`) and against the
updated record (`False`).
- `Debug.log` printing all 33 fields.
-}
-- TAGS: elm-spec, d-atexp-record, d-exprow-field, d-atpat-record, d-patrow-field, d-atexp-update
-- CHECK: f0000: 1000
-- CHECK: f0031: 31.5
-- CHECK: f0032: 'g'
-- CHECK: pattern: (1000,'g')
-- CHECK: update: '!'
-- CHECK: eq self: True
-- CHECK: eq updated: False
-- CHECK: show: { f0000 = 1000, f0001 = 1.5, f0002 = 'c', f0003 = "3s", f0004 = True, f0005 = 1005, f0006 = 6.5, f0007 = 'h', f0008 = "8s", f0009 = False, f0010 = 1010, f0011 = 11.5, f0012 = 'm', f0013 = "13s", f0014 = True, f0015 = 1015, f0016 = 16.5, f0017 = 'r', f0018 = "18s", f0019 = False, f0020 = 1020, f0021 = 21.5, f0022 = 'w', f0023 = "23s", f0024 = True, f0025 = 1025, f0026 = 26.5, f0027 = 'b', f0028 = "28s", f0029 = False, f0030 = 1030, f0031 = 31.5, f0032 = 'g' }
import Html exposing (text)
type alias R =
{ f0000 : Int
, f0001 : Float
, f0002 : Char
, f0003 : String
, f0004 : Bool
, f0005 : Int
, f0006 : Float
, f0007 : Char
, f0008 : String
, f0009 : Bool
, f0010 : Int
, f0011 : Float
, f0012 : Char
, f0013 : String
, f0014 : Bool
, f0015 : Int
, f0016 : Float
, f0017 : Char
, f0018 : String
, f0019 : Bool
, f0020 : Int
, f0021 : Float
, f0022 : Char
, f0023 : String
, f0024 : Bool
, f0025 : Int
, f0026 : Float
, f0027 : Char
, f0028 : String
, f0029 : Bool
, f0030 : Int
, f0031 : Float
, f0032 : Char
}
make : Int -> R
make base =
{ f0000 = (base + 999)
, f0001 = (toFloat base + 1.5 - 1)
, f0002 = ((if base == 1 then 'c' else '?'))
, f0003 = ((if base == 1 then "3s" else "?"))
, f0004 = (modBy 2 (base + 3) == 0)
, f0005 = (base + 1004)
, f0006 = (toFloat base + 6.5 - 1)
, f0007 = ((if base == 1 then 'h' else '?'))
, f0008 = ((if base == 1 then "8s" else "?"))
, f0009 = (modBy 2 (base + 8) == 0)
, f0010 = (base + 1009)
, f0011 = (toFloat base + 11.5 - 1)
, f0012 = ((if base == 1 then 'm' else '?'))
, f0013 = ((if base == 1 then "13s" else "?"))
, f0014 = (modBy 2 (base + 13) == 0)
, f0015 = (base + 1014)
, f0016 = (toFloat base + 16.5 - 1)
, f0017 = ((if base == 1 then 'r' else '?'))
, f0018 = ((if base == 1 then "18s" else "?"))
, f0019 = (modBy 2 (base + 18) == 0)
, f0020 = (base + 1019)
, f0021 = (toFloat base + 21.5 - 1)
, f0022 = ((if base == 1 then 'w' else '?'))
, f0023 = ((if base == 1 then "23s" else "?"))
, f0024 = (modBy 2 (base + 23) == 0)
, f0025 = (base + 1024)
, f0026 = (toFloat base + 26.5 - 1)
, f0027 = ((if base == 1 then 'b' else '?'))
, f0028 = ((if base == 1 then "28s" else "?"))
, f0029 = (modBy 2 (base + 28) == 0)
, f0030 = (base + 1029)
, f0031 = (toFloat base + 31.5 - 1)
, f0032 = ((if base == 1 then 'g' else '?'))
}
viaPat : R -> ( Int, Char )
viaPat { f0000, f0032 } =
( f0000, f0032 )
upd : R -> R
upd r =
{ r | f0032 = '!' }
main =
let
base =
1 + (Char.toCode 'b' - Char.toCode 'a') - 1
r =
make base
_ =
Debug.log "f0000" (r.f0000)
_ =
Debug.log "f0031" (r.f0031)
_ =
Debug.log "f0032" (r.f0032)
_ =
Debug.log "pattern" (viaPat r)
_ =
Debug.log "update" ((upd r).f0032)
_ =
Debug.log "eq self" (r == make base)
_ =
Debug.log "eq updated" (r == upd r)
_ =
Debug.log "show" (r)
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_WideRecord33Test, 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.
| Check | Expected (CHECK) | Lean evaluator | Proved by |
|---|---|---|---|
f0000 | 1000 | 1000 | t_elm_WideRecord33Test |
f0031 | 31.5 | 31.5 | t_elm_WideRecord33Test |
f0032 | 'g' | 'g' | t_elm_WideRecord33Test |
pattern | (1000,'g') | (1000,'g') | t_elm_WideRecord33Test |
update | '!' | '!' | t_elm_WideRecord33Test |
eq self | True | True | t_elm_WideRecord33Test |
eq updated | False | False | t_elm_WideRecord33Test |
show | { f0000 = 1000, f0001 = 1.5, f0002 = 'c', f0003 = "3s", f0004 = True, f0005 = 1005, f0006 = 6.5, f0007 = 'h', f0008 = "8s", f0009 = False, f0010 = 1010, f0011 = 11.5, f0012 = 'm', f0013 = "13s", f0014 = True, f0015 = 1015, f0016 = 16.5, f0017 = 'r', f0018 = "18s", f0019 = False, f0020 = 1020, f0021 = 21.5, f0022 = 'w', f0023 = "23s", f0024 = True, f0025 = 1025, f0026 = 26.5, f0027 = 'b', f0028 = "28s", f0029 = False, f0030 = 1030, f0031 = 31.5, f0032 = 'g' } | { f0000 = 1000, f0001 = 1.5, f0002 = 'c', f0003 = "3s", f0004 = True, f0005 = 1005, f0006 = 6.5, f0007 = 'h', f0008 = "8s", f0009 = False, f0010 = 1010, f0011 = 11.5, f0012 = 'm', f0013 = "13s", f0014 = True, f0015 = 1015, f0016 = 16.5, f0017 = 'r', f0018 = "18s", f0019 = False, f0020 = 1020, f0021 = 21.5, f0022 = 'w', f0023 = "23s", f0024 = True, f0025 = 1025, f0026 = 26.5, f0027 = 'b', f0028 = "28s", f0029 = False, f0030 = 1030, f0031 = 31.5, f0032 = 'g' } | t_elm_WideRecord33Test |
/-- tests/elm/src/WideRecord33Test.elm -/
def g_elm_WideRecord33Test : Program := {
name := "WideRecord33Test", source := "tests/elm/src",
exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
types := [],
aliases := [("R", some ["f0000", "f0001", "f0002", "f0003", "f0004", "f0005", "f0006", "f0007", "f0008", "f0009", "f0010", "f0011", "f0012", "f0013", "f0014", "f0015", "f0016", "f0017", "f0018", "f0019", "f0020", "f0021", "f0022", "f0023", "f0024", "f0025", "f0026", "f0027", "f0028", "f0029", "f0030", "f0031", "f0032"])],
defs := [
.fn "make" [pv "base"] (recE [("f0000", .atexp (.paren (bin "+" (v "base") (i 999)))), ("f0001", .atexp (.paren (bin "-" (bin "+" (ap (v "toFloat") [v "base"]) (.atexp (.scon (.float 15 (-1))))) (.atexp (.scon (.intF 1)))))), ("f0002", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (.atexp (chA 'c')) (.atexp (chA '?'))))))), ("f0003", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (str "3s") (str "?")))))), ("f0004", .atexp (.paren (bin "==" (ap (v "modBy") [i 2, .atexp (.paren (bin "+" (v "base") (i 3)))]) (i 0)))), ("f0005", .atexp (.paren (bin "+" (v "base") (i 1004)))), ("f0006", .atexp (.paren (bin "-" (bin "+" (ap (v "toFloat") [v "base"]) (.atexp (.scon (.float 65 (-1))))) (.atexp (.scon (.intF 1)))))), ("f0007", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (.atexp (chA 'h')) (.atexp (chA '?'))))))), ("f0008", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (str "8s") (str "?")))))), ("f0009", .atexp (.paren (bin "==" (ap (v "modBy") [i 2, .atexp (.paren (bin "+" (v "base") (i 8)))]) (i 0)))), ("f0010", .atexp (.paren (bin "+" (v "base") (i 1009)))), ("f0011", .atexp (.paren (bin "-" (bin "+" (ap (v "toFloat") [v "base"]) (.atexp (.scon (.float 115 (-1))))) (.atexp (.scon (.intF 1)))))), ("f0012", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (.atexp (chA 'm')) (.atexp (chA '?'))))))), ("f0013", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (str "13s") (str "?")))))), ("f0014", .atexp (.paren (bin "==" (ap (v "modBy") [i 2, .atexp (.paren (bin "+" (v "base") (i 13)))]) (i 0)))), ("f0015", .atexp (.paren (bin "+" (v "base") (i 1014)))), ("f0016", .atexp (.paren (bin "-" (bin "+" (ap (v "toFloat") [v "base"]) (.atexp (.scon (.float 165 (-1))))) (.atexp (.scon (.intF 1)))))), ("f0017", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (.atexp (chA 'r')) (.atexp (chA '?'))))))), ("f0018", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (str "18s") (str "?")))))), ("f0019", .atexp (.paren (bin "==" (ap (v "modBy") [i 2, .atexp (.paren (bin "+" (v "base") (i 18)))]) (i 0)))), ("f0020", .atexp (.paren (bin "+" (v "base") (i 1019)))), ("f0021", .atexp (.paren (bin "-" (bin "+" (ap (v "toFloat") [v "base"]) (.atexp (.scon (.float 215 (-1))))) (.atexp (.scon (.intF 1)))))), ("f0022", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (.atexp (chA 'w')) (.atexp (chA '?'))))))), ("f0023", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (str "23s") (str "?")))))), ("f0024", .atexp (.paren (bin "==" (ap (v "modBy") [i 2, .atexp (.paren (bin "+" (v "base") (i 23)))]) (i 0)))), ("f0025", .atexp (.paren (bin "+" (v "base") (i 1024)))), ("f0026", .atexp (.paren (bin "-" (bin "+" (ap (v "toFloat") [v "base"]) (.atexp (.scon (.float 265 (-1))))) (.atexp (.scon (.intF 1)))))), ("f0027", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (.atexp (chA 'b')) (.atexp (chA '?'))))))), ("f0028", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (str "28s") (str "?")))))), ("f0029", .atexp (.paren (bin "==" (ap (v "modBy") [i 2, .atexp (.paren (bin "+" (v "base") (i 28)))]) (i 0)))), ("f0030", .atexp (.paren (bin "+" (v "base") (i 1029)))), ("f0031", .atexp (.paren (bin "-" (bin "+" (ap (v "toFloat") [v "base"]) (.atexp (.scon (.float 315 (-1))))) (.atexp (.scon (.intF 1)))))), ("f0032", .atexp (.paren (.atexp (.paren (ifte (bin "==" (v "base") (i 1)) (.atexp (chA 'g')) (.atexp (chA '?')))))))]),
.fn "viaPat" [precord [("f0000", "f0000"), ("f0032", "f0032")]] (tup2 (v "f0000") (v "f0032")),
.fn "upd" [pv "r"] (updE "r" [("f0032", .atexp (chA '!'))]),
.fn "main" [] (letDefs [.fn "base" [] (bin "-" (bin "+" (i 1) (.atexp (.paren (bin "-" (ap (qv "Char" "toCode") [.atexp (chA 'b')]) (ap (qv "Char" "toCode") [.atexp (chA 'a')]))))) (i 1)), .fn "r" [] (ap (v "make") [v "base"]), .pat pw (ap (qv "Debug" "log") [str "f0000", .atexp (.paren (.atexp (access (A (v "r")) "f0000")))]), .pat pw (ap (qv "Debug" "log") [str "f0031", .atexp (.paren (.atexp (access (A (v "r")) "f0031")))]), .pat pw (ap (qv "Debug" "log") [str "f0032", .atexp (.paren (.atexp (access (A (v "r")) "f0032")))]), .pat pw (ap (qv "Debug" "log") [str "pattern", .atexp (.paren (ap (v "viaPat") [v "r"]))]), .pat pw (ap (qv "Debug" "log") [str "update", .atexp (.paren (.atexp (access (.paren (ap (v "upd") [v "r"])) "f0032")))]), .pat pw (ap (qv "Debug" "log") [str "eq self", .atexp (.paren (bin "==" (v "r") (ap (v "make") [v "base"])))]), .pat pw (ap (qv "Debug" "log") [str "eq updated", .atexp (.paren (bin "==" (v "r") (ap (v "upd") [v "r"])))]), .pat pw (ap (qv "Debug" "log") [str "show", .atexp (.paren (v "r"))])] (ap (v "text") [str "done"])) ],
checks := [
chk .check "f0000: 1000" .int,
chk .check "f0031: 31.5" .float,
chk .check "f0032: 'g'" .char,
chk .check "pattern: (1000,'g')" .data,
chk .check "update: '!'" .char,
chk .check "eq self: True" .data,
chk .check "eq updated: False" .data,
chk .check "show: { f0000 = 1000, f0001 = 1.5, f0002 = 'c', f0003 = \"3s\", f0004 = True, f0005 = 1005, f0006 = 6.5, f0007 = 'h', f0008 = \"8s\", f0009 = False, f0010 = 1010, f0011 = 11.5, f0012 = 'm', f0013 = \"13s\", f0014 = True, f0015 = 1015, f0016 = 16.5, f0017 = 'r', f0018 = \"18s\", f0019 = False, f0020 = 1020, f0021 = 21.5, f0022 = 'w', f0023 = \"23s\", f0024 = True, f0025 = 1025, f0026 = 26.5, f0027 = 'b', f0028 = \"28s\", f0029 = False, f0030 = 1030, f0031 = 31.5, f0032 = 'g' }" .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_WideRecord33Test 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_WideRecord33Test 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_WideRecord33Test states that the program has a meaning by r:p-program, with both premises, and ident_elm_WideRecord33Test that its specialisation is unique and is the reduced program above, both with no hypothesis about principality. One of these theorems is proved by native_decide ([native]).