Rule 58sm-topdec-portout
Comments
The variables of the annotation are made explicit, as for an annotated value. The argument of must be a type variable, so port send : String -> Cmd Msg does not elaborate, nor does port send : Cmd msg, which has no payload, nor port send : Int -> Int
-> Cmd msg. Since excludes type variables, is the only variable of , and the closure generalises it. The type is that of the initial basis; a type of a program spelt Cmd is a different type. A port is a value of status , so it is used and exposed like any other value; records its direction and payload type, by which Chapter 8 gives it its meaning, and Chapter 9 requires the names of the ports of a program to be distinct. Thus port send : Char -> Cmd msg does not elaborate, while port
send : List { id : Int, name : String } -> Cmd msg does.
TeX source
\defnrule[r:sm-topdec-portout]
{U \text{ is new for } \ty \text{ in } C \premsep \jdg{C + U}{\ty}{\tau} \\ \tau = \tau' \rightarrow \alpha\,\sbtCmd \premsep \Port(\tau')}
{\jdg{C}{\kw{port}\ \var\ \kw{:}\ \ty}{\{\var \mapsto (\Clos_C \tau, \isv)\}\ \text{in}\ \Env,\ \{\var \mapsto (\smdirout, \tau')\}}}Tests (13)
- elm / CovPortOutgoingJSONValueTestA port module declaring an outgoing port that sends a `Json.Encode.Value`.
- elm / CovPortOutgoingUnitTestA port module declaring an outgoing port that sends `()`.
- elm / OutgoingPortTuple3KeepsRunningTestA program that sends a 3-tuple through an outgoing port keeps running afterwards.
- elm / OutgoingPortTuple3TestTests that a program with an outgoing port whose payload is a 3-tuple `( String, String, List String )` compiles and runs.
- elm / PortAliasEchoTestAn outgoing port whose type is written through a type alias, `port echoOut : Out msg` with `type alias Out msg = Payload -> Cmd msg`, sends its record payload, and the record comes back unchanged through an incoming port.
- elm / PortEchoTestAn `Int` sent out through an outgoing port comes back unchanged through an incoming port.
- elm / PortEncodingEncodeBoolTestA port module declaring an outgoing port that carries `Bool` compiles and runs.
- elm / PortEncodingEncodeFloatTestA port module declaring an outgoing port that carries `Float` compiles and runs.
- elm / PortEncodingEncodeMaybeRecordTestA port module declaring an outgoing port that carries `Maybe { x : Int }` compiles and runs.
- elm / PortEncodingEncodeTuple2TestA port module declaring an outgoing port that carries `( Int, String )` compiles and runs.
- elm / PortEncodingPortWithArrayTestA port module declaring an outgoing port that carries `Array Int` compiles and runs.
- elm / PortProblemCharPayloadTestA port whose payload type is `Char` is rejected with a PORT ERROR naming the port and the `Char` type.
- elm / StandardA92BytesPortDeclarationTestA port module may declare an outgoing and an incoming port whose payload type is `Bytes`.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:sm-topdec-portout] in its title.
A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.