Elm Exactly
Results / elm /

PortPipeBytesTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:rule e-dec-bytesrule e-enc-bytesrule p-in-acceptrule p-outbasis Bytes.Bytes

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
A byte sequence received at `Bytes` goes out again as the same byte sequence.

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 passes every value it receives straight
back out. No function of elm/bytes is used: within the book's basis a program can have a `Bytes`
value only from the boundary.

A Standard Definition of Elm?, rules e-dec-bytes and e-enc-bytes (ruling A92): a byte sequence
decodes at `Bytes` as the value of its bytes, and a `Bytes` value is sent as its byte sequence.
The empty sequence is a byte sequence too. <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

fail
compile failed (exit 1):
Compiling ...-- PORT ERROR ---------------------------------------- src/PortPipeBytesTest.elm

The `bytesOut` port is trying to transmit a `Bytes` value:

33| port bytesOut : 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/PortPipeBytesTest.elm

The `bytesIn` port is trying to transmit a `Bytes` value:

30| 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

fail
compile failed (exit 1):
Compiling ...-- PORT ERROR ---------------------------------------- src/PortPipeBytesTest.elm

The `bytesOut` port is trying to transmit a `Bytes` value:

33| port bytesOut : 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/PortPipeBytesTest.elm

The `bytesIn` port is trying to transmit a `Bytes` value:

30| 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

fail
compile failed (exit 1):
Compiling ...-- PORT ERROR ---------------------------------------- src/PortPipeBytesTest.elm

The `bytesOut` port is trying to transmit a `Bytes` value:

33| port bytesOut : 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/PortPipeBytesTest.elm

The `bytesIn` port is trying to transmit a `Bytes` value:

30| 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

fail
compile failed (exit 1):
Success! Compiled 1 module.
-- MISSING DEPENDENCY ----------------------------------------------------------

These pass `Bytes` between Elm and JavaScript:

    port `bytesIn` in PortPipeBytesTest
    port `bytesOut` in PortPipeBytesTest

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/PortPipeBytesTest] in its title.

Source

The -- CHECK: lines give the expected output.

port module PortPipeBytesTest exposing (main)
{-| A byte sequence received at `Bytes` goes out again as the same byte sequence.
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 passes every value it receives straight
back out. No function of elm/bytes is used: within the book's basis a program can have a `Bytes`
value only from the boundary.
A Standard Definition of Elm?, rules e-dec-bytes and e-enc-bytes (ruling A92): a byte sequence
decodes at `Bytes` as the value of its bytes, and a `Bytes` value is sent as its byte sequence.
The empty sequence is a byte sequence too. <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-accept, p-out, b:Bytes.Bytes
-- HOST-SEND: bytesIn bytes(00 ff 10)
-- HOST-SEND: bytesIn bytes()
-- CHECK: bytesOut sent: bytes(00 ff 10)
-- CHECK: bytesOut sent: bytes()
import Bytes exposing (Bytes)
import Platform
port bytesIn : (Bytes -> msg) -> Sub msg
port bytesOut : Bytes -> Cmd msg
type Msg
= Got Bytes
init : () -> ( (), Cmd Msg )
init _ =
( (), Cmd.none )
update : Msg -> () -> ( (), Cmd Msg )
update (Got v) model =
( model, bytesOut v )
subscriptions : () -> Sub Msg
subscriptions _ =
bytesIn Got
main : Program () () 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_PortPipeBytesTest, 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
bytesOut sentbytes(00 ff 10) (the test now says bytes())bytes(00 ff 10) or bytes()t_elm_PortPipeBytesTest
bytesOut sentbytes()bytes(00 ff 10) or bytes()t_elm_PortPipeBytesTest
/-- tests/elm/src/PortPipeBytesTest.elm -/
def g_elm_PortPipeBytesTest : Program := {
  name := "PortPipeBytesTest", 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, .bytes)],
  defs := [
    .fn "init" [pw] (tup2 (.atexp .unit) (qv "Cmd" "none")),
    .fn "update" [.paren (pcon "Got" [pv "v"]), pv "model"] (tup2 (v "model") (ap (v "bytesOut") [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 PortPipeBytesTest. -/
def w_elm_PortPipeBytesTest : Prog.WorkerTest := {
  prog := g_elm_PortPipeBytesTest,
  flagsType := .unit,
  flags := .null,
  host := .feed "bytesIn" [(.bytes [0, 255, 16]), (.bytes [])],
  sent := [("bytesOut", (.bytes [0, 255, 16])), ("bytesOut", (.bytes []))],
  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_PortPipeBytesTest 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_PortPipeBytesTest 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_PortPipeBytesTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_PortPipeBytesTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.