# Html Msg vs Html msg?

**URL:** <https://discourse.elm-lang.org/t/html-msg-vs-html-msg/2758>\
**Category:** Learn\
**Created:** [December 13, 2018, 4:19pm UTC](https://discourse.elm-lang.org/t/html-msg-vs-html-msg/2758 "2018-12-13T16:19:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidnel34](https://avatars.discourse-cdn.com/v4/letter/d/73ab20/32.png) [@davidnel34](https://discourse.elm-lang.org/u/davidnel34)\
**Post date:** [December 13, 2018, 4:19pm UTC](https://discourse.elm-lang.org/t/html-msg-vs-html-msg/2758/1 "2018-12-13T16:19:32Z")

</div>

I can’t seem to figure out when you would use Html msg over Html Msg. Clarification and a bit of the internals will be appreciated!

---

<div class="post-metadata">

**Author:** ![rupert](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/rupert/32/1775_2.png) [@rupert](https://discourse.elm-lang.org/u/rupert)\
**Post date:** [December 13, 2018, 4:35pm UTC](https://discourse.elm-lang.org/t/html-msg-vs-html-msg/2758/2 "2018-12-13T16:35:39Z")

</div>

The lower case `msg` is called a type variable.

The upper case `Msg` is called a concrete type - its something your application has defined.

So we might have:

```
view : Html msg
view = div [] []

```

and

```
type Msg = Click

view : Html Msg
view = div [onClick Click] []

```

The first one doesn’t produce any events, so its type variable is not bound to anything yet.  
The second one produces events of your `Msg` type, and its type variable is bound to that.

Also note that this compiles ok:

```
innerView : Html msg
innerView = div [] []

view : Html Msg
view = div [onClick Click] [innerView]

```

Here `innerView` needs to have the type `Html Msg` to be included in some HTML with that type. That’s ok because the free `msg` variable can be bound to `Msg` and the type checking passes.

Make sense?

---

<div class="post-metadata">

**Author:** ![davidnel34](https://avatars.discourse-cdn.com/v4/letter/d/73ab20/32.png) [@davidnel34](https://discourse.elm-lang.org/u/davidnel34)\
**Post date:** [December 13, 2018, 4:38pm UTC](https://discourse.elm-lang.org/t/html-msg-vs-html-msg/2758/3 "2018-12-13T16:38:10Z")

</div>

Yes! I finally understand it better now. Thank you for your time!

---

<div class="post-metadata">

**Author:** ![joelq](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/joelq/32/445_2.png) [@joelq](https://discourse.elm-lang.org/u/joelq)\
**Post date:** [December 13, 2018, 6:39pm UTC](https://discourse.elm-lang.org/t/html-msg-vs-html-msg/2758/4 "2018-12-13T18:39:38Z")

</div>

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](https://github.com/rtfeldman/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 🙂

---

<div class="post-metadata">

**Author:** ![davidnel34](https://avatars.discourse-cdn.com/v4/letter/d/73ab20/32.png) [@davidnel34](https://discourse.elm-lang.org/u/davidnel34)\
**Post date:** [December 14, 2018, 11:25am UTC](https://discourse.elm-lang.org/t/html-msg-vs-html-msg/2758/5 "2018-12-14T11:25:58Z")

</div>

Thank you for your thorough response!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [December 24, 2018, 11:26am UTC](https://discourse.elm-lang.org/t/html-msg-vs-html-msg/2758/6 "2018-12-24T11:26:07Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
