PortPipeBytesRejectTest
Checks, in A Standard Definition of Elm?:rule e-dec-bytesrule e-enc-bytesrule p-in-rejectrule p-in-acceptrule e-enc-tuplebasis Bytes.Bytes
Translated into Lean for the mechanisation of the book: see its Lean translation.
A JSON value sent to a `Bytes` port is rejected, whatever it holds. 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 e-dec-bytes and p-in-reject (rulings A71, A92): only a byte sequence decodes at `Bytes`; a string of hex digits, an array of numbers and `null` are JSON values, and are rejected at the boundary. The byte sequence after them is the first value the program receives. <https://elm-test-suite.netlify.app/standard/rules/e-dec-bytes> Elm 0.19.1 rejects every port whose type holds `Bytes` (PORT ERROR); Appendix E of the book says Elm/JS has no representation for a byte sequence at the host.
Results
elm-0.19.1
failcompile failed (exit 1):
Compiling ...-- PORT ERROR ---------------------------------- src/PortPipeBytesRejectTest.elm
The `bytesOut` port is trying to transmit a `Bytes` value:
34| port bytesOut : ( Int, Bytes ) -> Cmd msg
^^^^^^^^
I cannot handle that. The types that CAN flow in and out of Elm include:
Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, tuples, records, and
JSON values.
Since JSON values can flow through, you can use JSON encoders and decoders to
allow other types through as well. More advanced users often just do everything
with encoders and decoders for more control and better errors.
Hint: Ports are not a traditional FFI, so if you have tons of annoying ports,
definitely read <https://elm-lang.org/0.19.1/ports> to learn how they are meant
to work. They require a different mindset!
-- PORT ERROR ---------------------------------- src/PortPipeBytesRejectTest.elm
The `bytesIn` port is trying to transmit a `Bytes` value:
31| port bytesIn : (Bytes -> msg) -> Sub msg
^^^^^^^
I cannot handle that. The types that CAN flow in and out of Elm include:
Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, tuples, records, and
JSON values.
Since JSON values can flow through, you can use JSON encoders and decoders to
allow other types through as well. More advanced users often just do everything
with encoders and decoders for more control and better errors.
Hint: Ports are not a traditional FFI, so if you have tons of annoying ports,
definitely read <https://elm-lang.org/0.19.1/ports> to learn how they are meant
to work. They require a different mindset!
Detected problems in 1 module.
elm-0.19.2
failcompile failed (exit 1):
Compiling ...-- PORT ERROR ---------------------------------- src/PortPipeBytesRejectTest.elm
The `bytesOut` port is trying to transmit a `Bytes` value:
34| port bytesOut : ( Int, Bytes ) -> Cmd msg
^^^^^^^^
I cannot handle that. The types that CAN flow in and out of Elm include:
Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, tuples, records, and
JSON values.
Since JSON values can flow through, you can use JSON encoders and decoders to
allow other types through as well. More advanced users often just do everything
with encoders and decoders for more control and better errors.
Hint: Ports are not a traditional FFI, so if you have tons of annoying ports,
definitely read <https://elm-lang.org/0.19.2/ports> to learn how they are meant
to work. They require a different mindset!
-- PORT ERROR ---------------------------------- src/PortPipeBytesRejectTest.elm
The `bytesIn` port is trying to transmit a `Bytes` value:
31| port bytesIn : (Bytes -> msg) -> Sub msg
^^^^^^^
I cannot handle that. The types that CAN flow in and out of Elm include:
Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, tuples, records, and
JSON values.
Since JSON values can flow through, you can use JSON encoders and decoders to
allow other types through as well. More advanced users often just do everything
with encoders and decoders for more control and better errors.
Hint: Ports are not a traditional FFI, so if you have tons of annoying ports,
definitely read <https://elm-lang.org/0.19.2/ports> to learn how they are meant
to work. They require a different mindset!
Detected problems in 1 module.
elm-0.19.3
failcompile failed (exit 1):
Compiling ...-- PORT ERROR ---------------------------------- src/PortPipeBytesRejectTest.elm
The `bytesOut` port is trying to transmit a `Bytes` value:
34| port bytesOut : ( Int, Bytes ) -> Cmd msg
^^^^^^^^
I cannot handle that. The types that CAN flow in and out of Elm include:
Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, tuples, records, and
JSON values.
Since JSON values can flow through, you can use JSON encoders and decoders to
allow other types through as well. More advanced users often just do everything
with encoders and decoders for more control and better errors.
Hint: Ports are not a traditional FFI, so if you have tons of annoying ports,
definitely read <https://elm-lang.org/0.19.3/ports> to learn how they are meant
to work. They require a different mindset!
-- PORT ERROR ---------------------------------- src/PortPipeBytesRejectTest.elm
The `bytesIn` port is trying to transmit a `Bytes` value:
31| port bytesIn : (Bytes -> msg) -> Sub msg
^^^^^^^
I cannot handle that. The types that CAN flow in and out of Elm include:
Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, tuples, records, and
JSON values.
Since JSON values can flow through, you can use JSON encoders and decoders to
allow other types through as well. More advanced users often just do everything
with encoders and decoders for more control and better errors.
Hint: Ports are not a traditional FFI, so if you have tons of annoying ports,
definitely read <https://elm-lang.org/0.19.3/ports> to learn how they are meant
to work. They require a different mindset!
Detected problems in 1 module.
lamdera-1.5.0
failcompile failed (exit 1):
Success! Compiled 1 module.
-- MISSING DEPENDENCY ----------------------------------------------------------
These pass `Bytes` between Elm and JavaScript:
port `bytesIn` in PortPipeBytesRejectTest
port `bytesOut` in PortPipeBytesRejectTest
Sending `Bytes` through ports and flags is something Lamdera adds to Elm, and it
needs the lamdera/codecs package, which this project does not depend on. Add it
with:
lamdera install lamdera/codecs
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/PortPipeBytesRejectTest] in its title.
Source
The -- CHECK: lines give the expected output.
port module PortPipeBytesRejectTest exposing (main)
{-| A JSON value sent to a `Bytes` port is rejected, whatever it holds.
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 e-dec-bytes and p-in-reject (rulings A71, A92): only a byte
sequence decodes at `Bytes`; a string of hex digits, an array of numbers and `null` are JSON
values, and are rejected at the boundary. The byte sequence after them is the first value the
program receives. <https://elm-test-suite.netlify.app/standard/rules/e-dec-bytes>
Elm 0.19.1 rejects every port whose type holds `Bytes` (PORT ERROR); Appendix E of the book says
Elm/JS has no representation for a byte sequence at the host.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, e-dec-bytes, e-enc-bytes, p-in-reject, p-in-accept, e-enc-tuple, b:Bytes.Bytes
-- HOST-SEND: bytesIn "00ff10"
-- HOST-SEND: bytesIn [0,255,16]
-- HOST-SEND: bytesIn null
-- HOST-SEND: bytesIn bytes(01)
-- CHECK: bytesOut sent: [1,bytes(01)]
import Bytes exposing (Bytes)
import Platform
port bytesIn : (Bytes -> msg) -> Sub msg
port bytesOut : ( Int, Bytes ) -> Cmd msg
type Msg
= Got Bytes
init : () -> ( Int, Cmd Msg )
init _ =
( 0, Cmd.none )
update : Msg -> Int -> ( Int, Cmd Msg )
update (Got v) model =
( model + 1, bytesOut ( model + 1, v ) )
subscriptions : Int -> Sub Msg
subscriptions _ =
bytesIn 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_PortPipeBytesRejectTest, 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 |
|---|---|---|---|
bytesOut sent | [1,bytes(01)] | [1,bytes(01)] | t_elm_PortPipeBytesRejectTest |
/-- tests/elm/src/PortPipeBytesRejectTest.elm -/
def g_elm_PortPipeBytesRejectTest : Program := {
name := "PortPipeBytesRejectTest", source := "tests/elm/src",
exposing := (.items [.var "main"]), imports := [⟨"Bytes", "Bytes", some (.items [.tycon "Bytes"])⟩, ⟨"Platform", "Platform", none⟩],
types := [("Msg", [("Got", 1)])],
aliases := [],
ports := [("bytesIn", .inn, .bytes), ("bytesOut", .out, (.tuple2 .int .bytes))],
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 "bytesOut") [tup2 (bin "+" (v "model") (i 1)) (v "v")])),
.fn "subscriptions" [pw] (ap (v "bytesIn") [c "Got"]),
.fn "main" [] (ap (qv "Platform" "worker") [recE [("init", v "init"), ("update", v "update"), ("subscriptions", v "subscriptions")]]) ],
checks := [ ] }
/-- The worker test of PortPipeBytesRejectTest. -/
def w_elm_PortPipeBytesRejectTest : Prog.WorkerTest := {
prog := g_elm_PortPipeBytesRejectTest,
flagsType := .unit,
flags := .null,
host := .feed "bytesIn" [(.str "00ff10"), (Eff.BVal.array [(.num (Eff.jnum (0) (0))), (.num (Eff.jnum (255) (0))), (.num (Eff.jnum (16) (0)))]), .null, (.bytes [1])],
sent := [("bytesOut", (Eff.BVal.array [(.num (Eff.jnum (1) (0))), (.bytes [1])]))],
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_PortPipeBytesRejectTest 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_PortPipeBytesRejectTest 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_PortPipeBytesRejectTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_PortPipeBytesRejectTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.