Elm Exactly
Results / elm /

CharAstralRecordFieldTest

Tags:elm-spec

Checks, in A Standard Definition of Elm?:rule d-atexp-updaterule d-atexp-recordbasis Char.toCodefigure core-escapes

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
An astral `Char` (code point above 0xFFFF) in a record field keeps its code
point, next to an `Int` field and after a record update, and a record holding
one is equal to a record literal with the same fields.

A Standard Definition of Elm?, the basis entry Char.toCode: the code of the character with code
point h is h, and `\u{h}` denotes that character. <https://elm-test-suite.netlify.app/standard/basis/Char/toCode>

Results

elm-0.19.1

passran in 55 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
rec_c: 128512
rec_n: 7
rec_updated: 119070
rec_eq: True

elm-0.19.2

passran in 67 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
rec_c: 128512
rec_n: 7
rec_updated: 119070
rec_eq: True

elm-0.19.3

passran in 44 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
rec_updated: 119070
rec_eq: True
rec_n: 7
rec_c: 128512

lamdera-1.5.0

passran in 58 ms
Output
rec_updated: 119070
rec_eq: True
rec_n: 7
rec_c: 128512

Discussions

Discuss this testยทSearch the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module CharAstralRecordFieldTest exposing (main)
{-| An astral `Char` (code point above 0xFFFF) in a record field keeps its code
point, next to an `Int` field and after a record update, and a record holding
one is equal to a record literal with the same fields.
A Standard Definition of Elm?, the basis entry Char.toCode: the code of the character with code
point h is h, and `\u{h}` denotes that character. <https://elm-test-suite.netlify.app/standard/basis/Char/toCode>
-}
-- TAGS: elm-spec, d-atexp-update, d-atexp-record, b:Char.toCode, fig:core-escapes
-- CHECK: rec_c: 128512
-- CHECK: rec_n: 7
-- CHECK: rec_updated: 119070
-- CHECK: rec_eq: True
import Html exposing (text)
type alias Glyph =
{ c : Char, n : Int }
mk : Char -> Int -> Glyph
mk c n =
{ c = c, n = n }
main =
let
g =
mk '๐Ÿ˜€' 7
h =
{ g | c = '\u{1D11E}' }
_ =
Debug.log "rec_c" (Char.toCode g.c)
_ =
Debug.log "rec_n" g.n
_ =
Debug.log "rec_updated" (Char.toCode h.c)
_ =
Debug.log "rec_eq" (g == { c = '๐Ÿ˜€', n = 7 })
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_CharAstralRecordFieldTest, in StandardElmMech/Generated/Elm_CaseS.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
rec_c128512128512t_elm_CharAstralRecordFieldTest
rec_n77t_elm_CharAstralRecordFieldTest
rec_updated119070119070t_elm_CharAstralRecordFieldTest
rec_eqTrueTruet_elm_CharAstralRecordFieldTest
/-- tests/elm/src/CharAstralRecordFieldTest.elm -/
def g_elm_CharAstralRecordFieldTest : Program := {
  name := "CharAstralRecordFieldTest", source := "tests/elm/src",
  exposing := (.items [.var "main"]), imports := [โŸจ"Html", "Html", some (.items [.var "text"])โŸฉ],
  types := [],
  aliases := [("Glyph", some ["c", "n"])],
  defs := [
    .fn "mk" [pv "c", pv "n"] (recE [("c", v "c"), ("n", v "n")]),
    .fn "main" [] (letDefs [.fn "g" [] (ap (v "mk") [.atexp (chA '๐Ÿ˜€'), i 7]), .fn "h" [] (updE "g" [("c", .atexp (chA '๐„ž'))]), .pat pw (ap (qv "Debug" "log") [str "rec_c", .atexp (.paren (ap (qv "Char" "toCode") [.atexp (access (A (v "g")) "c")]))]), .pat pw (ap (qv "Debug" "log") [str "rec_n", .atexp (access (A (v "g")) "n")]), .pat pw (ap (qv "Debug" "log") [str "rec_updated", .atexp (.paren (ap (qv "Char" "toCode") [.atexp (access (A (v "h")) "c")]))]), .pat pw (ap (qv "Debug" "log") [str "rec_eq", .atexp (.paren (bin "==" (v "g") (recE [("c", .atexp (chA '๐Ÿ˜€')), ("n", i 7)])))])] (ap (v "text") [str "done"])) ],
  checks := [
    chk .check "rec_c: 128512" .int,
    chk .check "rec_n: 7" .int,
    chk .check "rec_updated: 119070" .int,
    chk .check "rec_eq: 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_CharAstralRecordFieldTest 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_CharAstralRecordFieldTest 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_CharAstralRecordFieldTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_CharAstralRecordFieldTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.