Hi,

I am looking for a help explaining type annotations. I am, in particular, 
puzzled by the *correct* annotation for the "update" function here: 
https://github.com/ondras/elm-irc/blob/master/src/Irc/App.elm#L24

Now the code is pretty complex, so I shall probably explain how this works. 
The file above is part of my IRC client library that

1) connects to an IRC server via WebSocket (using an irrelevant tiny server 
proxy),

2) sends IRC messages through this channel,

3) parses incoming IRC data.

One of the APIs that I offer is the "Irc.App.program", which behaves almost 
exactly as Html.App.program: you give it an app descriptor (init, update, 
view, onIrc) and it runs The Elm Architecture using these callbacks. There 
are two differences to Html.App.program:

a) the "onIrc" function that is executed when an IRC message arrives from 
the server (its results are handled the same way as in the "update"),

b) both "update" and "onIrc" callbacks are passed an additional argument, 
the "CommandSet", which can be used to send IRC messages back to the server.

The correct type annotation for my "update" is

update : x -> model -> CommandSet (Msg x) -> (model, Cmd (Msg x))

"Msg" is a union type that differentiates messages coming from IRC and 
messages coming from the rendered HTML.

  - The returned command: Why do I need to write "Cmd (Msg x)" and not "Cmd 
x", as in the Html.App.program's annotation?
  - The first argument (message): Why do I need to write "x" and not "Msg", 
when I know that my "update" will process only Msg types?
  - Why does the "x" need to be the same for the first argument and the 
returned command?

Thanks for shedding some light on type annotations with unknown/custom type 
constructors.


O.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to