Elm Exactly
Results / elm /

OutgoingPortTuple3KeepsRunningTest

Tags:elm-spec

Checks, in A Standard Definition of Elm?:rule sm-topdec-portoutrule p-disp-outrule p-disp-taskrule p-proc-sleeprule p-proc-message

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
A program that sends a 3-tuple through an outgoing port keeps running afterwards.

The port's payload is `( String, Int, List String )`. Nothing subscribes to the port. The command
is batched with a 10 ms sleep, and the program must log "sent" before it and "after" when the
sleep ends.

Results

elm-0.19.1

passran in 63 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
OutgoingPortTuple3Test: "sent"
OutgoingPortTuple3Test: "after"

elm-0.19.2

passran in 61 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
OutgoingPortTuple3Test: "sent"
OutgoingPortTuple3Test: "after"

elm-0.19.3

passran in 80 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
OutgoingPortTuple3Test: "sent"
OutgoingPortTuple3Test: "after"

lamdera-1.5.0

passran in 76 ms
Output
OutgoingPortTuple3Test: "sent"
OutgoingPortTuple3Test: "after"

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

port module OutgoingPortTuple3KeepsRunningTest exposing (main)
{-| A program that sends a 3-tuple through an outgoing port keeps running afterwards.
The port's payload is `( String, Int, List String )`. Nothing subscribes to the port. The command
is batched with a 10 ms sleep, and the program must log "sent" before it and "after" when the
sleep ends.
-}
-- TAGS: elm-spec, sm-topdec-portout, p-disp-out, p-disp-task, p-proc-sleep, p-proc-message
-- MODE-GUARD: a Char equality must give the same answer as under --optimize
-- NO-SKIP: an edge case every compiler must run
-- CHECK: OutgoingPortTuple3Test: "sent"
-- CHECK: OutgoingPortTuple3Test: "after"
import Platform
import Process
import Task
port out3 : ( String, Int, List String ) -> Cmd msg
type Msg
= After
init : () -> ( (), Cmd Msg )
init _ =
let
_ =
Debug.log "OutgoingPortTuple3Test" "sent"
in
( ()
, Cmd.batch
[ out3 ( "name.elm", 3, [ "x", "y" ] )
, Task.perform (\_ -> After) (Process.sleep 10)
]
)
update : Msg -> () -> ( (), Cmd Msg )
update After model =
let
_ =
Debug.log "OutgoingPortTuple3Test" "after"
in
( model, Cmd.none )
main : Program () () Msg
main =
Platform.worker
{ init = init
, update = update
, 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_OutgoingPortTuple3KeepsRunningTest, 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
OutgoingPortTuple3Test"sent" (the test now says "after")"sent" or "after"t_elm_OutgoingPortTuple3KeepsRunningTest
OutgoingPortTuple3Test"after""sent" or "after"t_elm_OutgoingPortTuple3KeepsRunningTest
/-- tests/elm/src/OutgoingPortTuple3KeepsRunningTest.elm -/
def g_elm_OutgoingPortTuple3KeepsRunningTest : Program := {
  name := "OutgoingPortTuple3KeepsRunningTest", source := "tests/elm/src",
  exposing := (.items [.var "main"]), imports := [⟨"Platform", "Platform", none⟩, ⟨"Process", "Process", none⟩, ⟨"Task", "Task", none⟩],
  types := [("Msg", [("After", 0)])],
  aliases := [],
  ports := [("out3", .out, (.tuple3 .string .int (.list .string)))],
  defs := [
    .fn "init" [pw] (letDefs [.pat pw (ap (qv "Debug" "log") [str "OutgoingPortTuple3Test", str "sent"])] (tup2 (.atexp .unit) (ap (qv "Cmd" "batch") [listE [ap (v "out3") [tup3 (str "name.elm") (i 3) (listE [str "x", str "y"])], ap (qv "Task" "perform") [.atexp (.paren (lams [pw] (c "After"))), .atexp (.paren (ap (qv "Process" "sleep") [.atexp (.scon (.intF 10))]))]]]))),
    .fn "update" [pcA "After", pv "model"] (letDefs [.pat pw (ap (qv "Debug" "log") [str "OutgoingPortTuple3Test", str "after"])] (tup2 (v "model") (qv "Cmd" "none"))),
    .fn "main" [] (ap (qv "Platform" "worker") [recE [("init", v "init"), ("update", v "update"), ("subscriptions", lams [pw] (qv "Sub" "none"))]]) ],
  checks := [
    chk .check "OutgoingPortTuple3Test: \"sent\"" .string,
    chk .check "OutgoingPortTuple3Test: \"after\"" .string ] }

/-- The worker test of OutgoingPortTuple3KeepsRunningTest. -/
def w_elm_OutgoingPortTuple3KeepsRunningTest : Prog.WorkerTest := {
  prog := g_elm_OutgoingPortTuple3KeepsRunningTest,
  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_OutgoingPortTuple3KeepsRunningTest 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_OutgoingPortTuple3KeepsRunningTest 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_OutgoingPortTuple3KeepsRunningTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_OutgoingPortTuple3KeepsRunningTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.