Elm Exactly
Results / elm /

StandardA88PortNegativeZeroTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:rule e-enc-floatrule e-dec-float

Translated into Lean for the mechanisation of the book: see its Lean translation.

elm-0.19.1 failelm-0.19.2 failelm-0.19.3 faillamdera-1.5.0 fail
`-0` sent out through a port arrives as `+0`.

A Standard Definition of Elm?, ruling A88: a value crosses a port as JSON, where `-0` is the number
`0`; at `Float` it decodes as `+0`. <https://elm-test-suite.netlify.app/standard/rules/e-enc-float>
<https://elm-test-suite.netlify.app/standard/rules/e-dec-float>

The test's host sends each `echoOut` value straight back on `echoIn`. Elm 0.19.1 passes `-0`
through, so `1 / v` is `-Infinity`.

Results

elm-0.19.1

failran in 86 ms
Missing pattern: 1 / received > 0: True
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
1 / received > 0: False

elm-0.19.2

failran in 53 ms
Missing pattern: 1 / received > 0: True
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
1 / received > 0: False

elm-0.19.3

failran in 68 ms
Missing pattern: 1 / received > 0: True
--- output ---
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
1 / received > 0: False

lamdera-1.5.0

failran in 67 ms
Missing pattern: 1 / received > 0: True
--- output ---
1 / received > 0: False

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

port module StandardA88PortNegativeZeroTest exposing (main)
{-| `-0` sent out through a port arrives as `+0`.
A Standard Definition of Elm?, ruling A88: a value crosses a port as JSON, where `-0` is the number
`0`; at `Float` it decodes as `+0`. <https://elm-test-suite.netlify.app/standard/rules/e-enc-float>
<https://elm-test-suite.netlify.app/standard/rules/e-dec-float>
The test's host sends each `echoOut` value straight back on `echoIn`. Elm 0.19.1 passes `-0`
through, so `1 / v` is `-Infinity`.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, e-enc-float, e-dec-float
-- CHECK: 1 / received > 0: True
import Process
import Task
port echoOut : Float -> Cmd msg
port echoIn : (Float -> msg) -> Sub msg
type Msg
= Start
| Got Float
init : () -> ( (), Cmd Msg )
init _ =
( (), Task.perform (always Start) (Process.sleep 10) )
update : Msg -> () -> ( (), Cmd Msg )
update msg model =
case msg of
Start ->
( model, echoOut (-(0 / 1)) )
Got v ->
let
_ =
Debug.log "1 / received > 0" (1 / v > 0)
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_StandardA88PortNegativeZeroTest, 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.

CheckExpected (CHECK)Lean evaluatorProved by
1 / received > 0TrueTruet_elm_StandardA88PortNegativeZeroTest
/-- tests/elm/src/StandardA88PortNegativeZeroTest.elm -/
def g_elm_StandardA88PortNegativeZeroTest : Program := {
  name := "StandardA88PortNegativeZeroTest", 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, .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 (v "echoOut") [.atexp (.paren (.atexp (neg (.paren (bin "/" (.atexp (.scon (.intF 0))) (.atexp (.scon (.intF 1))))))))])), (pcon "Got" [pv "v"], letDefs [.pat pw (ap (qv "Debug" "log") [str "1 / received > 0", .atexp (.paren (bin ">" (bin "/" (.atexp (.scon (.intF 1))) (v "v")) (.atexp (.scon (.intF 0)))))])] (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 "1 / received > 0: True" .data ] }

/-- The worker test of StandardA88PortNegativeZeroTest. -/
def w_elm_StandardA88PortNegativeZeroTest : Prog.WorkerTest := {
  prog := g_elm_StandardA88PortNegativeZeroTest,
  flagsType := .unit,
  flags := .null,
  host := .echo "echoOut" "echoIn",
  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_StandardA88PortNegativeZeroTest 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_StandardA88PortNegativeZeroTest 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_StandardA88PortNegativeZeroTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_StandardA88PortNegativeZeroTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.