That works out to have a type of “Cmd msg”, where I assume msg is a lower
case type variable. What is the type of msg in (Cmd msg) which send
returns? Because its returned by the “update” function, it should be Cmd
Msg (capital M message, which is an actual type in the example file), but I
don’t see how one of those is returned from Websocket.send. Websocket.send
doesn’t know about the types in the websocket example, how could it return
one of them?

Yes, msg there is a type variable. That the result of Websocket.send after
supplying two strings is still polymorphic (having a type variable) means
that it will instantiate to every concrete type as needed in a specific
context. So if you return it from an update functions that has (for example
due to other case branches) a return type Cmd Msg, then the msg will be
instantiated to Msg and everything will work out. The function
Websocket.send does not need to know about the concrete type Msg for this
to go well.

This is an issue for me because I want to pass a partial application of
WebSocket.send to a subcomponent, which will save the ftn into a state
structure. So passing (Websocket.send “someaddress”), into an init
function, which would put it into a struct like so:

type alias Model =
  { sendf : (String -> Cmd msg)
  , otherstuff: String
  }

Then in my update function in the subcomponent the plan would be to call
“sendf”. Problem is the compiler wants me to specify the type of “msg”, and
I have no idea what that might be.

The solution should be to define the above like this instead:

type alias Model msg =
  { sendf : (String -> Cmd msg)
  , otherstuff: String
  }

Note the parametrisation of Model over msg.
​

2016-08-13 18:04 GMT+02:00 Ben Burdette <[email protected]>:

>
> I'm looking at the websockets example here:  http://elm-lang.org/examples/
> websockets
>
> According to the source (https://github.com/elm-lang/
> websocket/blob/1.0.1/src/WebSocket.elm), it looks like the type of
> Websocket.send is (String->String->Cmd msg), and in the update ftn of the
> websocket example, what's being returned is (Websocket.send <string1>
> <string2>).
>
> That works out to have a type of "Cmd msg", where I assume msg is a lower
> case type variable.  What is the type of msg in (Cmd msg) which send
> returns?  Because its returned by the "update" function, it should be Cmd
> Msg (capital M message, which is an actual type in the example file), but I
> don't see how one of those is returned from Websocket.send.  Websocket.send
> doesn't know about the types in the websocket example, how could it return
> one of them?
>
> This is an issue for me because I want to pass a partial application of
> WebSocket.send to a subcomponent, which will save the ftn into a state
> structure.  So passing (Websocket.send "someaddress"), into an init
> function, which would put it into a struct like so:
>
> type alias Model =
>   { sendf : (String -> Cmd msg)
>   , otherstuff: String
>   }
>
> Then in my update function in the subcomponent the plan would be to call
> "sendf".  Problem is the compiler wants me to specify the type of "msg",
> and I have no idea what that might be.
>
>
> --
> 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.
>

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