Elm Exactly
Results / elm /

ListLiteralDebugLogKindTest

Tags:elm-spec

Checks, in A Standard Definition of Elm?:rule d-exp-lambdarule d-atexp-tuplerule d-app-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
Values returned by `Debug.log` keep their value when used in a closure, a tuple, a function
argument, a list literal and a `::` cons.

`d` is `Debug.log "d" 66108864`. The tests compare it, through each of those uses, against
67108864 (2^26) or add it up: `sumLit` sums `[ d, d ]` with a local `sum`. A `Float`, a `Char`
and a `Bool` from `Debug.log` are each put in a one- or two-element list literal and read back,
with a local `all` or by logging the list.

Results

elm-0.19.1

passran in 76 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
fl: 1.5
d: 66108864
c: 'q'
b: True
capture: True
tuple: True
call: True
sumLit: 132217728
consOp: True
floatLit: True
charLit: ['q','q']
boolLit: True

elm-0.19.2

passran in 66 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
fl: 1.5
d: 66108864
c: 'q'
b: True
capture: True
tuple: True
call: True
sumLit: 132217728
consOp: True
floatLit: True
charLit: ['q','q']
boolLit: True

elm-0.19.3

passran in 43 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
fl: 1.5
floatLit: True
d: 66108864
capture: True
consOp: True
sumLit: 132217728
call: True
tuple: True
c: 'q'
charLit: ['q','q']
b: True
boolLit: True

lamdera-1.5.0

passran in 74 ms
Output
fl: 1.5
floatLit: True
d: 66108864
capture: True
consOp: True
sumLit: 132217728
call: True
tuple: True
c: 'q'
charLit: ['q','q']
b: True
boolLit: True

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module ListLiteralDebugLogKindTest exposing (main)
{-| Values returned by `Debug.log` keep their value when used in a closure, a tuple, a function
argument, a list literal and a `::` cons.
`d` is `Debug.log "d" 66108864`. The tests compare it, through each of those uses, against
67108864 (2^26) or add it up: `sumLit` sums `[ d, d ]` with a local `sum`. A `Float`, a `Char`
and a `Bool` from `Debug.log` are each put in a one- or two-element list literal and read back,
with a local `all` or by logging the list.
-}
-- TAGS: elm-spec, d-exp-lambda, d-atexp-tuple, d-app-con
-- MODE-GUARD: a Char equality must give the same answer as under --optimize
-- NO-SKIP: an edge case every compiler must run
-- CHECK-DAG: fl: 1.5
-- CHECK-DAG: d: 66108864
-- CHECK-DAG: c: 'q'
-- CHECK-DAG: b: True
-- CHECK-DAG: capture: True
-- CHECK-DAG: tuple: True
-- CHECK-DAG: call: True
-- CHECK-DAG: sumLit: 132217728
-- CHECK-DAG: consOp: True
-- CHECK-DAG: floatLit: True
-- CHECK-DAG: charLit: ['q','q']
-- CHECK-DAG: boolLit: True
import Platform
first : ( a, b ) -> a
first ( x, _ ) =
x
sum : List Int -> Int
sum xs =
case xs of
[] ->
0
x :: rest ->
x + sum rest
all : (a -> Bool) -> List a -> Bool
all p xs =
case xs of
[] ->
True
x :: rest ->
p x && all p rest
addTo : Int -> Int -> Int
addTo a b =
a + b
report : ()
report =
let
d =
Debug.log "d" 66108864
f =
\x -> x + d < 67108864 + 5
_ =
Debug.log "capture" (f 3)
_ =
Debug.log "tuple" (first ( d, 1 ) < 67108864)
_ =
Debug.log "call" (addTo d 1 < 67108864)
_ =
Debug.log "sumLit" (sum [ d, d ])
_ =
Debug.log "consOp" (all (\h -> h < 67108864) (d :: []))
fl =
Debug.log "fl" 1.5
_ =
Debug.log "floatLit" (all (\h -> h < 2.0) [ fl ])
c =
Debug.log "c" 'q'
_ =
Debug.log "charLit" [ c, c ]
b =
Debug.log "b" True
_ =
Debug.log "boolLit" (all identity [ b ])
in
()
main : Program () () ()
main =
Platform.worker
{ init = \_ -> ( report, Cmd.none )
, 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_ListLiteralDebugLogKindTest, in StandardElmMech/Generated/Worker01.lean). Lean evaluates its modules by the rules of Chapter 7, starts it by r:p-init with no flags (null, A72), 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.

Out of date. The test, or a module it imports, has changed since this translation was made; the translation, and so its theorems, describe the program as it was until the mechanisation is rebuilt.

CheckExpected (CHECK)Lean evaluatorProved by
fl1.5 (no longer a CHECK line of the test)1.5t_elm_ListLiteralDebugLogKindTest
d66108864 (no longer a CHECK line of the test)66108864 or 66108864t_elm_ListLiteralDebugLogKindTest
c'q' (no longer a CHECK line of the test)'q't_elm_ListLiteralDebugLogKindTest
bTrue (no longer a CHECK line of the test)Truet_elm_ListLiteralDebugLogKindTest
captureTrue (no longer a CHECK line of the test)Truet_elm_ListLiteralDebugLogKindTest
tupleTrue (no longer a CHECK line of the test)Truet_elm_ListLiteralDebugLogKindTest
callTrue (no longer a CHECK line of the test)Truet_elm_ListLiteralDebugLogKindTest
sumLit132217728 (no longer a CHECK line of the test)132217728t_elm_ListLiteralDebugLogKindTest
consOpTrue (no longer a CHECK line of the test)Truet_elm_ListLiteralDebugLogKindTest
floatLitTrue (no longer a CHECK line of the test)Truet_elm_ListLiteralDebugLogKindTest
charLit['q','q'] (no longer a CHECK line of the test)['q','q']t_elm_ListLiteralDebugLogKindTest
boolLitTrue (no longer a CHECK line of the test)Truet_elm_ListLiteralDebugLogKindTest
/-- tests/elm/src/ListLiteralDebugLogKindTest.elm -/
def g_elm_ListLiteralDebugLogKindTest : Program := {
  name := "ListLiteralDebugLogKindTest", source := "tests/elm/src",
  exposing := (.items [.var "main"]), imports := [⟨"Platform", "Platform", none⟩],
  types := [],
  aliases := [],
  defs := [
    .fn "first" [ptup2 (P (pv "x")) (P pw)] (v "x"),
    .fn "sum" [pv "xs"] (caseOf (v "xs") [(P (listP []), i 0), (.cons (P (pv "x")) (P (pv "rest")), bin "+" (v "x") (ap (v "sum") [v "rest"]))]),
    .fn "all" [pv "p", pv "xs"] (caseOf (v "xs") [(P (listP []), c "True"), (.cons (P (pv "x")) (P (pv "rest")), andalso (ap (v "p") [v "x"]) (ap (v "all") [v "p", v "rest"]))]),
    .fn "addTo" [pv "a", pv "b"] (bin "+" (v "a") (v "b")),
    .fn "report" [] (letDefs [.fn "d" [] (ap (qv "Debug" "log") [str "d", .atexp (.scon (.intF 66108864))]), .fn "d$Int" [] (ap (qv "Debug" "log") [str "d", i 66108864]), .fn "f" [] (lams [pv "x"] (bin "<" (bin "+" (v "x") (v "d")) (bin "+" (.atexp (.scon (.intF 67108864))) (.atexp (.scon (.intF 5)))))), .pat pw (ap (qv "Debug" "log") [str "capture", .atexp (.paren (ap (v "f") [.atexp (.scon (.intF 3))]))]), .pat pw (ap (qv "Debug" "log") [str "tuple", .atexp (.paren (bin "<" (ap (v "first") [tup2 (v "d") (.atexp (.scon (.intF 1)))]) (.atexp (.scon (.intF 67108864)))))]), .pat pw (ap (qv "Debug" "log") [str "call", .atexp (.paren (bin "<" (ap (v "addTo") [v "d$Int", i 1]) (i 67108864)))]), .pat pw (ap (qv "Debug" "log") [str "sumLit", .atexp (.paren (ap (v "sum") [listE [v "d$Int", v "d$Int"]]))]), .pat pw (ap (qv "Debug" "log") [str "consOp", .atexp (.paren (ap (v "all") [.atexp (.paren (lams [pv "h"] (bin "<" (v "h") (.atexp (.scon (.intF 67108864)))))), .atexp (.paren (bin "::" (v "d") (listE [])))]))]), .fn "fl" [] (ap (qv "Debug" "log") [str "fl", .atexp (.scon (.float 15 (-1)))]), .pat pw (ap (qv "Debug" "log") [str "floatLit", .atexp (.paren (ap (v "all") [.atexp (.paren (lams [pv "h"] (bin "<" (v "h") (.atexp (.scon (.float 20 (-1))))))), listE [v "fl"]]))]), .fn "c" [] (ap (qv "Debug" "log") [str "c", .atexp (chA 'q')]), .pat pw (ap (qv "Debug" "log") [str "charLit", listE [v "c", v "c"]]), .fn "b" [] (ap (qv "Debug" "log") [str "b", c "True"]), .pat pw (ap (qv "Debug" "log") [str "boolLit", .atexp (.paren (ap (v "all") [v "identity", listE [v "b"]]))])] (.atexp .unit)),
    .fn "main" [] (ap (qv "Platform" "worker") [recE [("init", lams [pw] (tup2 (v "report") (qv "Cmd" "none"))), ("update", lams [pw, pv "model"] (tup2 (v "model") (qv "Cmd" "none"))), ("subscriptions", lams [pw] (qv "Sub" "none"))]]) ],
  checks := [
    chk .check "fl: 1.5" .float,
    chk .check "d: 66108864" .float,
    chk .check "c: 'q'" .char,
    chk .check "b: True" .data,
    chk .check "capture: True" .data,
    chk .check "tuple: True" .data,
    chk .check "call: True" .data,
    chk .check "sumLit: 132217728" .int,
    chk .check "consOp: True" .data,
    chk .check "floatLit: True" .data,
    chk .check "charLit: ['q','q']" .data,
    chk .check "boolLit: True" .data ] }

/-- The worker test of ListLiteralDebugLogKindTest. -/
def w_elm_ListLiteralDebugLogKindTest : Prog.WorkerTest := {
  prog := g_elm_ListLiteralDebugLogKindTest,
  flagsType := .unit,
  flags := .null,
  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_ListLiteralDebugLogKindTest 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_ListLiteralDebugLogKindTest 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_ListLiteralDebugLogKindTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_ListLiteralDebugLogKindTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.