One may model the case that one has some html that is static (in the sense it never gives rise to an event) by using type Html Never. Then, when including that piece of html in a view, one will typically have to transform it into something of type Html Msg for an application specific Msg type. One way to do so is to use Html.App.map with a function of type Never -> Msg. Typically \_ -> NoOp. But sometimes this may mean one has to artificially introduce NoOp into the application specific Msg type, which may otherwise not have a need for a NoOp concept. Also, it's lame to write down that \_ -> NoOp function when it is anyway never going to be actually applied. And moreover, writing Html.App.map (\_ -> NoOp) does not actually enforce that the input is of type Html Never, it would accept any other Html Whatever as well.
The function static : Html Never -> Html msg here remedies all that.
For example, we then have that static (Html.text "abcdef") has type Html Msg for whatever Msg type we want, and at the same time we have expressed that the html being embedded there is not allowed to ever actually emit any messages (even if one later refactors and replaces Html.text "abcdef" by another expression or by an argument of the view function, for example).
A motivating use case is in this thread on the mailing list.
In short:
One may model the case that one has some html that is static (in the sense it never gives rise to an event) by using type
Html Never
. Then, when including that piece of html in a view, one will typically have to transform it into something of typeHtml Msg
for an application specificMsg
type. One way to do so is to useHtml.App.map
with a function of typeNever -> Msg
. Typically\_ -> NoOp
. But sometimes this may mean one has to artificially introduceNoOp
into the application specificMsg
type, which may otherwise not have a need for aNoOp
concept. Also, it's lame to write down that\_ -> NoOp
function when it is anyway never going to be actually applied. And moreover, writingHtml.App.map (\_ -> NoOp)
does not actually enforce that the input is of typeHtml Never
, it would accept any otherHtml Whatever
as well.The function
static : Html Never -> Html msg
here remedies all that.For example, we then have that
static (Html.text "abcdef")
has typeHtml Msg
for whateverMsg
type we want, and at the same time we have expressed that the html being embedded there is not allowed to ever actually emit any messages (even if one later refactors and replacesHtml.text "abcdef"
by another expression or by an argument of the view function, for example).