Elm Exactly
Results / elm /

PortPipeRejectTest

Tags:elm-spec

Checks, in A Standard Definition of Elm?:rule p-in-rejectrule p-in-acceptrule e-dec-intrule e-enc-intrule e-enc-tuple

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 that do not decode at an incoming port's type are rejected, and the program goes on.

The test driver sends each `HOST-SEND` value in on the incoming port and prints each value the
program sends out (plans/host-pipe-tests.md). The program numbers the values it receives, from 1,
and sends each out with its number, so a rejected value shows as a number not used.

A Standard Definition of Elm?, rules p-in-reject and e-dec-int: `1.5`, the string `"3"` and
`null` do not decode at `Int`, so they are rejected and the program never sees them; `3` and `4`
are the first and second values it receives. <https://elm-test-suite.netlify.app/standard/rules/p-in-reject>

Results

elm-0.19.1

passran in 61 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
numberOut sent: [1,3]
numberOut sent: [2,4]

elm-0.19.2

passran in 59 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
numberOut sent: [1,3]
numberOut sent: [2,4]

elm-0.19.3

passran in 81 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
numberOut sent: [1,3]
numberOut sent: [2,4]

lamdera-1.5.0

passran in 59 ms
Output
numberOut sent: [1,3]
numberOut sent: [2,4]

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

port module PortPipeRejectTest exposing (main)
{-| Values that do not decode at an incoming port's type are rejected, and the program goes on.
The test driver sends each `HOST-SEND` value in on the incoming port and prints each value the
program sends out (plans/host-pipe-tests.md). The program numbers the values it receives, from 1,
and sends each out with its number, so a rejected value shows as a number not used.
A Standard Definition of Elm?, rules p-in-reject and e-dec-int: `1.5`, the string `"3"` and
`null` do not decode at `Int`, so they are rejected and the program never sees them; `3` and `4`
are the first and second values it receives. <https://elm-test-suite.netlify.app/standard/rules/p-in-reject>
-}
-- TAGS: elm-spec, p-in-reject, p-in-accept, e-dec-int, e-enc-int, e-enc-tuple
-- HOST-SEND: numberIn 1.5
-- HOST-SEND: numberIn "3"
-- HOST-SEND: numberIn null
-- HOST-SEND: numberIn 3
-- HOST-SEND: numberIn 4
-- CHECK: numberOut sent: [1,3]
-- CHECK: numberOut sent: [2,4]
import Platform
port numberIn : (Int -> msg) -> Sub msg
port numberOut : ( Int, Int ) -> Cmd msg
type Msg
= Got Int
init : () -> ( Int, Cmd Msg )
init _ =
( 0, Cmd.none )
update : Msg -> Int -> ( Int, Cmd Msg )
update (Got v) model =
( model + 1, numberOut ( model + 1, v ) )
subscriptions : Int -> Sub Msg
subscriptions _ =
numberIn Got
main : Program () Int Msg
main =
Platform.worker
{ init = init
, update = update
, subscriptions = subscriptions
}

Lean translation

This worker program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm? (g_elm_PortPipeRejectTest, 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.

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
numberOut sent[1,3] (the test now says [2,4])[1,3] or [2,4]t_elm_PortPipeRejectTest
numberOut sent[2,4][1,3] or [2,4]t_elm_PortPipeRejectTest
/-- tests/elm/src/PortPipeRejectTest.elm -/
def g_elm_PortPipeRejectTest : Program := {
  name := "PortPipeRejectTest", source := "tests/elm/src",
  exposing := (.items [.var "main"]), imports := [⟨"Platform", "Platform", none⟩],
  types := [("Msg", [("Got", 1)])],
  aliases := [],
  ports := [("numberIn", .inn, .int), ("numberOut", .out, (.tuple2 .int .int))],
  defs := [
    .fn "init" [pw] (tup2 (i 0) (qv "Cmd" "none")),
    .fn "update" [.paren (pcon "Got" [pv "v"]), pv "model"] (tup2 (bin "+" (v "model") (i 1)) (ap (v "numberOut") [tup2 (bin "+" (v "model") (i 1)) (v "v")])),
    .fn "subscriptions" [pw] (ap (v "numberIn") [c "Got"]),
    .fn "main" [] (ap (qv "Platform" "worker") [recE [("init", v "init"), ("update", v "update"), ("subscriptions", v "subscriptions")]]) ],
  checks := [ ] }

/-- The worker test of PortPipeRejectTest. -/
def w_elm_PortPipeRejectTest : Prog.WorkerTest := {
  prog := g_elm_PortPipeRejectTest,
  flagsType := .unit,
  flags := .null,
  host := .feed "numberIn" [(.num (Eff.jnum (15) (-1))), (.str "3"), .null, (.num (Eff.jnum (3) (0))), (.num (Eff.jnum (4) (0)))],
  sent := [("numberOut", (Eff.BVal.array [(.num (Eff.jnum (1) (0))), (.num (Eff.jnum (3) (0)))])), ("numberOut", (Eff.BVal.array [(.num (Eff.jnum (2) (0))), (.num (Eff.jnum (4) (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_PortPipeRejectTest 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_PortPipeRejectTest 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_PortPipeRejectTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_PortPipeRejectTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.