Elm Exactly
Results / elm /

PolyChainDictLikeInsertChained5TimesWithTupleKeysConcreteCallerTest

Tags:elm-spec

Checks, in A Standard Definition of Elm?:rule s-valbind-varrule s-atexp-longvarrule 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
Tests a polymorphic `insert` on a list-like dictionary type, called five
times in a chain from a function with concrete `( String, Int )` keys and
`Int` values.

`size` looks only at the outermost constructor, returning 1 for any `Entry`,
so the logged value is 1 rather than the number of entries.

Results

elm-0.19.1

passran in 44 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
testValue: 1

elm-0.19.2

passran in 56 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
testValue: 1

elm-0.19.3

passran in 65 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
testValue: 1

lamdera-1.5.0

passran in 69 ms
Output
testValue: 1

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module PolyChainDictLikeInsertChained5TimesWithTupleKeysConcreteCallerTest exposing (..)
{-| Tests a polymorphic `insert` on a list-like dictionary type, called five
times in a chain from a function with concrete `( String, Int )` keys and
`Int` values.
`size` looks only at the outermost constructor, returning 1 for any `Entry`,
so the logged value is 1 rather than the number of entries.
-}
-- TAGS: elm-spec, s-valbind-var, s-atexp-longvar, d-pat-con
-- CHECK: testValue: 1
import Basics exposing (..)
import Char exposing (..)
import List exposing (..)
import Maybe exposing (..)
import String exposing (..)
import Html
type MyDict k v
= Empty
| Entry k v (MyDict k v)
insert : k -> v -> MyDict k v -> MyDict k v
insert key val dict =
Entry key val dict
size : MyDict k v -> Int
size d =
case d of
Empty ->
0
Entry _ _ _ ->
1
testValue : Int
testValue =
let
d0 =
Empty
d1 =
insert ( "k0", 0 ) 0 d0
d2 =
insert ( "k1", 1 ) 10 d1
d3 =
insert ( "k2", 2 ) 20 d2
d4 =
insert ( "k3", 3 ) 30 d3
d5 =
insert ( "k4", 4 ) 40 d4
in
size d5
main =
let
_ =
Debug.log "testValue" testValue
in
Html.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_PolyChainDictLikeInsertChained5TimesWithTupleKeysConcreteCallerTest, in StandardElmMech/Generated/Elm_PartialAppCh.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
testValue11t_elm_PolyChainDictLikeInsertChained5TimesWithTupleKeysConcreteCallerTest
/-- tests/elm/src/PolyChainDictLikeInsertChained5TimesWithTupleKeysConcreteCallerTest.elm -/
def g_elm_PolyChainDictLikeInsertChained5TimesWithTupleKeysConcreteCallerTest : Program := {
  name := "PolyChainDictLikeInsertChained5TimesWithTupleKeysConcreteCallerTest", source := "tests/elm/src",
  exposing := .all, imports := [⟨"Basics", "Basics", some .all⟩, ⟨"Char", "Char", some .all⟩, ⟨"List", "List", some .all⟩, ⟨"Maybe", "Maybe", some .all⟩, ⟨"String", "String", some .all⟩, ⟨"Html", "Html", none⟩],
  types := [("MyDict", [("Empty", 0), ("Entry", 3)])],
  aliases := [],
  defs := [
    .fn "insert" [pv "key", pv "val", pv "dict"] (ap (c "Entry") [v "key", v "val", v "dict"]),
    .fn "size" [pv "d"] (caseOf (v "d") [(P (pcA "Empty"), i 0), (pcon "Entry" [pw, pw, pw], i 1)]),
    .fn "testValue" [] (letDefs [.fn "d0" [] (c "Empty"), .fn "d1" [] (ap (v "insert") [tup2 (str "k0") (.atexp (.scon (.intF 0))), .atexp (.scon (.intF 0)), v "d0"]), .fn "d2" [] (ap (v "insert") [tup2 (str "k1") (.atexp (.scon (.intF 1))), .atexp (.scon (.intF 10)), v "d1"]), .fn "d3" [] (ap (v "insert") [tup2 (str "k2") (.atexp (.scon (.intF 2))), .atexp (.scon (.intF 20)), v "d2"]), .fn "d4" [] (ap (v "insert") [tup2 (str "k3") (.atexp (.scon (.intF 3))), .atexp (.scon (.intF 30)), v "d3"]), .fn "d5" [] (ap (v "insert") [tup2 (str "k4") (.atexp (.scon (.intF 4))), .atexp (.scon (.intF 40)), v "d4"])] (ap (v "size") [v "d5"])),
    .fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "testValue", v "testValue"])] (ap (qv "Html" "text") [str "done"])) ],
  checks := [
    chk .check "testValue: 1" .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_PolyChainDictLikeInsertChained5TimesWithTupleKeysConcreteCallerTest 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_PolyChainDictLikeInsertChained5TimesWithTupleKeysConcreteCallerTest 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_PolyChainDictLikeInsertChained5TimesWithTupleKeysConcreteCallerTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_PolyChainDictLikeInsertChained5TimesWithTupleKeysConcreteCallerTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.