MinimalPipeRecordTest
Tags:elm-spec
Checks, in A Standard Definition of Elm?:rule e-dec-recordrule e-enc-record
Translated into Lean for the mechanisation of the book: see its Lean translation.
A pipe at `{ a : Int }`: the value the driver sends in comes back out.
The simplest test of rules e-dec-record, e-enc-record of A Standard Definition of Elm?: the driver
sends `{"a":1}`. <https://elm-test-suite.netlify.app/standard/rules/e-dec-record>Results
elm-0.19.1
passran in 57 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
recordOut sent: {"a":1}
elm-0.19.2
passran in 59 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
recordOut sent: {"a":1}
elm-0.19.3
passran in 58 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
recordOut sent: {"a":1}
lamdera-1.5.0
passran in 66 msOutput
recordOut sent: {"a":1}
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/MinimalPipeRecordTest] in its title.
Source
The -- CHECK: lines give the expected output.
port module MinimalPipeRecordTest exposing (main)
{-| A pipe at `{ a : Int }`: the value the driver sends in comes back out.
The simplest test of rules e-dec-record, e-enc-record of A Standard Definition of Elm?: the driver
sends `{"a":1}`. <https://elm-test-suite.netlify.app/standard/rules/e-dec-record>
-}
-- TAGS: elm-spec, e-dec-record, e-enc-record
-- HOST-SEND: recordIn {"a":1}
-- CHECK: recordOut sent: {"a":1}
import Platform
port recordIn : ({ a : Int } -> msg) -> Sub msg
port recordOut : { a : Int } -> Cmd msg
type Msg
= Got { a : Int }
update : Msg -> () -> ( (), Cmd Msg )
update (Got v) model =
( model, recordOut v )
main : Program () () Msg
main =
Platform.worker
{ init = \_ -> ( (), Cmd.none )
, update = update
, subscriptions = \_ -> recordIn Got
}
Lean translation
This worker program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm? (g_elm_MinimalPipeRecordTest, 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 the test driver of a pipe test, which sends the test's HOST-SEND values on its incoming port, in order, and takes every value sent out. 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, and sends out the values of the CHECK lines “<port> sent: <value>”, in the order written. 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.
| Check | Expected (CHECK) | Lean evaluator | Proved by |
|---|---|---|---|
recordOut sent | {"a":1} | {"a":1} | t_elm_MinimalPipeRecordTest |
/-- tests/elm/src/MinimalPipeRecordTest.elm -/
def g_elm_MinimalPipeRecordTest : Program := {
name := "MinimalPipeRecordTest", source := "tests/elm/src",
exposing := (.items [.var "main"]), imports := [⟨"Platform", "Platform", none⟩],
types := [("Msg", [("Got", 1)])],
aliases := [],
ports := [("recordIn", .inn, (.record (.cons "a" .int .nil))), ("recordOut", .out, (.record (.cons "a" .int .nil)))],
defs := [
.fn "update" [.paren (pcon "Got" [pv "v"]), pv "model"] (tup2 (v "model") (ap (v "recordOut") [v "v"])),
.fn "main" [] (ap (qv "Platform" "worker") [recE [("init", lams [pw] (tup2 (.atexp .unit) (qv "Cmd" "none"))), ("update", v "update"), ("subscriptions", lams [pw] (ap (v "recordIn") [c "Got"]))]]) ],
checks := [ ] }
/-- The worker test of MinimalPipeRecordTest. -/
def w_elm_MinimalPipeRecordTest : Prog.WorkerTest := {
prog := g_elm_MinimalPipeRecordTest,
flagsType := .unit,
flags := .null,
host := .feed "recordIn" [(Eff.BVal.mkObj [("a", (.num (Eff.jnum (1) (0))))])],
sent := [("recordOut", (Eff.BVal.mkObj [("a", (.num (Eff.jnum (1) (0))))]))],
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_MinimalPipeRecordTest 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_MinimalPipeRecordTest 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_MinimalPipeRecordTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_MinimalPipeRecordTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.