Html Msg vs Html msg?

I think part of the confusion here is that there are two different things referred to as “message” in the Elm community.

  1. The generic idea of a value that represents an event in the outside world and that will eventually feed into your update function. It shows up as a type variable in several types where it is conventionally written as little “m” msg (e.g. Html msg, Cmd msg)
  2. A user-defined custom type named big “M” Msg

While there’s often a lot of overlap between the two, they are not the same. Msg isn’t a “magic” framework type and types like Html String or Html Int are valid. More subtly, larger projects such as elm-spa-example often have view functions that return values like Html Home.Msg or Html Article.Msg

While the lowercase msg variable name has good intentions of communicating “the type that would go here fills the role of a message (definition 1)”, my experience is that many people read it as “the type that would go here is going to be a Msg (definition 2)”.

Personally, I’ve started using Html a in my own code rather than Html msg to avoid this confusion :slight_smile:

3 Likes