I'm teaching myself elm and see (of course) many references to Html msg
--
I understand that this is a 'parameterised type', that is, that (as I understand it), the constructor of the type Html
takes a parameter -- much as List Char
does.
OK. But then in following along in some tutorials, I see they quickly change the msg
to be a custom type, often something like this (I'm doing this from memory, so please forgive me):
Html Msg
where Msg
might be defined as
type Msg =
Something | SomethingElse
I also see that here -- https://discourse.elm-lang.org/t/html-msg-vs-html-msg/2758 -- they say
The lower case msg is called a type variable. The upper case Msg is called a concrete type - its something your application has defined.
That answers my question part way, but could someone elaborate on what this means exactly? Because when I see something like List String
, I understand what String
is in this context, but I don't understand what msg
means in Html msg
.
Also, are we not changing the type of the return value of the function? That is, if the Elm runtime is expecting view
to return a certain type, and that type is Html msg
, if we change the return type to Html Whatever
, why does that work? (For instance, we can't change a function's return value from List String
to List Number
arbitrarily, right?)
Coming from a background in OOP and typed languages like C, TypeScript, etc, I would think that any Msg
would need to somehow be related to msg
, that is 'extend' it in some way to allow polymorphism. Obviously I'm looking at this the wrong way, and any explanation would be appreciated!