StandardA88PortNonFiniteTest
Checks, in A Standard Definition of Elm?:rule e-enc-float-nullrule e-enc-floatrule e-dec-nothing
Translated into Lean for the mechanisation of the book: see its Lean translation.
A NaN or an infinity sent out through a port arrives as JSON `null`. A Standard Definition of Elm?, ruling A88: a value crosses a port as JSON, which has no NaN or infinity, so a non-finite float goes out as `null`. <https://elm-test-suite.netlify.app/standard/rules/e-enc-float> The test's host sends each `echoOut` value straight back on `echoIn`, decoded as a `Maybe Float`: `null` is `Nothing`. Elm 0.19.1 passes NaN and `Infinity` to the host as JavaScript numbers, so they come back as `Just NaN` and `Just Infinity`.
Results
elm-0.19.1
failran in 57 msMissing pattern: got: Nothing (with 1 CHECK-SAME/CHECK-NEXT continuation(s)) --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. got: Just Infinity got: Just NaN
elm-0.19.2
failran in 74 msMissing pattern: got: Nothing (with 1 CHECK-SAME/CHECK-NEXT continuation(s)) --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. got: Just Infinity got: Just NaN
elm-0.19.3
failran in 72 msMissing pattern: got: Nothing (with 1 CHECK-SAME/CHECK-NEXT continuation(s)) --- output --- Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. got: Just Infinity got: Just NaN
lamdera-1.5.0
failran in 68 msMissing pattern: got: Nothing (with 1 CHECK-SAME/CHECK-NEXT continuation(s)) --- output --- got: Just Infinity got: Just NaN
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/StandardA88PortNonFiniteTest] in its title.
Source
The -- CHECK: lines give the expected output.
port module StandardA88PortNonFiniteTest exposing (main)
{-| A NaN or an infinity sent out through a port arrives as JSON `null`.
A Standard Definition of Elm?, ruling A88: a value crosses a port as JSON, which has no NaN or
infinity, so a non-finite float goes out as `null`. <https://elm-test-suite.netlify.app/standard/rules/e-enc-float>
The test's host sends each `echoOut` value straight back on `echoIn`, decoded as a `Maybe Float`:
`null` is `Nothing`. Elm 0.19.1 passes NaN and `Infinity` to the host as JavaScript numbers, so they
come back as `Just NaN` and `Just Infinity`.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, e-enc-float-null, e-enc-float, e-dec-nothing
-- CHECK: got: Nothing
-- CHECK-NEXT: got: Nothing
-- CHECK-NOT: Just
import Process
import Task
port echoOut : Float -> Cmd msg
port echoIn : (Maybe Float -> msg) -> Sub msg
type Msg
= Start
| Got (Maybe Float)
init : () -> ( (), Cmd Msg )
init _ =
( (), Task.perform (always Start) (Process.sleep 10) )
update : Msg -> () -> ( (), Cmd Msg )
update msg model =
case msg of
Start ->
( model, Cmd.batch [ echoOut (0 / 0), echoOut (1 / 0) ] )
Got v ->
let
_ =
Debug.log "got" (v)
in
( model, Cmd.none )
main : Program () () Msg
main =
Platform.worker
{ init = init
, update = update
, subscriptions = \_ -> echoIn 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_StandardA88PortNonFiniteTest, 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 runner's echo host, which sends every value delivered on echoOut back on echoIn, in order. 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.
| Check | Expected (CHECK) | Lean evaluator | Proved by |
|---|---|---|---|
got | Nothing | Nothing or Nothing | t_elm_StandardA88PortNonFiniteTest |
got | Nothing | Nothing or Nothing | t_elm_StandardA88PortNonFiniteTest |
Just | (no value) (no longer a CHECK line of the test) | (not logged) | t_elm_StandardA88PortNonFiniteTest |
/-- tests/elm/src/StandardA88PortNonFiniteTest.elm -/
def g_elm_StandardA88PortNonFiniteTest : Program := {
name := "StandardA88PortNonFiniteTest", source := "tests/elm/src",
exposing := (.items [.var "main"]), imports := [⟨"Process", "Process", none⟩, ⟨"Task", "Task", none⟩],
types := [("Msg", [("Start", 0), ("Got", 1)])],
aliases := [],
ports := [("echoOut", .out, .float), ("echoIn", .inn, (.maybe .float))],
defs := [
.fn "init" [pw] (tup2 (.atexp .unit) (ap (qv "Task" "perform") [.atexp (.paren (ap (v "always") [c "Start"])), .atexp (.paren (ap (qv "Process" "sleep") [.atexp (.scon (.intF 10))]))])),
.fn "update" [pv "msg", pv "model"] (caseOf (v "msg") [(P (pcA "Start"), tup2 (v "model") (ap (qv "Cmd" "batch") [listE [ap (v "echoOut") [.atexp (.paren (bin "/" (.atexp (.scon (.intF 0))) (.atexp (.scon (.intF 0)))))], ap (v "echoOut") [.atexp (.paren (bin "/" (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 0)))))]]])), (pcon "Got" [pv "v"], letDefs [.pat pw (ap (qv "Debug" "log") [str "got", .atexp (.paren (v "v"))])] (tup2 (v "model") (qv "Cmd" "none")))]),
.fn "main" [] (ap (qv "Platform" "worker") [recE [("init", v "init"), ("update", v "update"), ("subscriptions", lams [pw] (ap (v "echoIn") [c "Got"]))]]) ],
checks := [
chk .check "got: Nothing" .data,
chk .next "got: Nothing" .data ] }
/-- The worker test of StandardA88PortNonFiniteTest. -/
def w_elm_StandardA88PortNonFiniteTest : Prog.WorkerTest := {
prog := g_elm_StandardA88PortNonFiniteTest,
flagsType := .unit,
flags := .null,
host := .echo "echoOut" "echoIn",
checkNots := ["Just"],
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_StandardA88PortNonFiniteTest 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_StandardA88PortNonFiniteTest 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_StandardA88PortNonFiniteTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_StandardA88PortNonFiniteTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality. One of these theorems is proved by native_decide ([native]).