Elm Exactly
Results / elm /

StandardA92BytesPortDeclarationTest

Tags:elm19-bugelm-spec

Checks, in A Standard Definition of Elm?:rule sm-topdec-portoutrule sm-topdec-portinbasis 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 pass
A port module may declare an outgoing and an incoming port whose payload type is `Bytes`.

A Standard Definition of Elm?, ruling A92: `Bytes` is a payload type, so `Port(Bytes)` holds and
both declarations elaborate. <https://elm-test-suite.netlify.app/standard/static-modules#sec-static-modules-ports>

The ports are declared and never used: the program logs a constant and ends. Within the book's
basis no program can make a value of type `Bytes` (its functions lie outside the definition, and
no JSON flag decodes at `Bytes`), so this test checks only the declarations.
`PortPipeBytesTest` has the test driver send bytes in and checks what comes out. Elm 0.19.1
rejects a port whose type holds `Bytes`.

Results

elm-0.19.1

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

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

27| port echoIn : (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!

-- PORT ERROR ---------------------- src/StandardA92BytesPortDeclarationTest.elm

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

24| port echoOut : 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!

Detected problems in 1 module.

elm-0.19.2

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

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

27| port echoIn : (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!

-- PORT ERROR ---------------------- src/StandardA92BytesPortDeclarationTest.elm

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

24| port echoOut : 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!

Detected problems in 1 module.

elm-0.19.3

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

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

27| port echoIn : (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!

-- PORT ERROR ---------------------- src/StandardA92BytesPortDeclarationTest.elm

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

24| port echoOut : 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!

Detected problems in 1 module.

lamdera-1.5.0

passran in 40 ms
Output
declared: True

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

port module StandardA92BytesPortDeclarationTest exposing (main)
{-| A port module may declare an outgoing and an incoming port whose payload type is `Bytes`.
A Standard Definition of Elm?, ruling A92: `Bytes` is a payload type, so `Port(Bytes)` holds and
both declarations elaborate. <https://elm-test-suite.netlify.app/standard/static-modules#sec-static-modules-ports>
The ports are declared and never used: the program logs a constant and ends. Within the book's
basis no program can make a value of type `Bytes` (its functions lie outside the definition, and
no JSON flag decodes at `Bytes`), so this test checks only the declarations.
`PortPipeBytesTest` has the test driver send bytes in and checks what comes out. Elm 0.19.1
rejects a port whose type holds `Bytes`.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, sm-topdec-portout, sm-topdec-portin, b:Bytes.Bytes
-- CHECK: declared: True
import Bytes exposing (Bytes)
import Platform
port echoOut : Bytes -> Cmd msg
port echoIn : (Bytes -> msg) -> Sub msg
init : () -> ( (), Cmd msg )
init _ =
let
_ =
Debug.log "declared" True
in
( (), Cmd.none )
main : Program () () msg
main =
Platform.worker
{ init = init
, update = \_ model -> ( model, Cmd.none )
, subscriptions = \_ -> Sub.none
}

Lean translation

This worker program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm? (g_elm_StandardA92BytesPortDeclarationTest, 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 a host that sends nothing. 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
declaredTrueTruet_elm_StandardA92BytesPortDeclarationTest
/-- tests/elm/src/StandardA92BytesPortDeclarationTest.elm -/
def g_elm_StandardA92BytesPortDeclarationTest : Program := {
  name := "StandardA92BytesPortDeclarationTest", source := "tests/elm/src",
  exposing := (.items [.var "main"]), imports := [⟨"Bytes", "Bytes", some (.items [.tycon "Bytes"])⟩, ⟨"Platform", "Platform", none⟩],
  types := [],
  aliases := [],
  ports := [("echoOut", .out, .bytes), ("echoIn", .inn, .bytes)],
  defs := [
    .fn "init" [pw] (letDefs [.pat pw (ap (qv "Debug" "log") [str "declared", c "True"])] (tup2 (.atexp .unit) (qv "Cmd" "none"))),
    .fn "main" [] (ap (qv "Platform" "worker") [recE [("init", v "init"), ("update", lams [pw, pv "model"] (tup2 (v "model") (qv "Cmd" "none"))), ("subscriptions", lams [pw] (qv "Sub" "none"))]]) ],
  checks := [
    chk .check "declared: True" .data ] }

/-- The worker test of StandardA92BytesPortDeclarationTest. -/
def w_elm_StandardA92BytesPortDeclarationTest : Prog.WorkerTest := {
  prog := g_elm_StandardA92BytesPortDeclarationTest,
  flagsType := .unit,
  flags := .null,
  host := .none,
  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_StandardA92BytesPortDeclarationTest 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_StandardA92BytesPortDeclarationTest 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_StandardA92BytesPortDeclarationTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_StandardA92BytesPortDeclarationTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.