What is Html Msg

Can’t figure out the syntax here.
foo: String -> String -> String
foo is a function that takes two string args and returns string
Similarly,
bar: String -> (String -> String)
bar is a function that takes a String and returns a function that takes in a string and returns a string.

How do u say/describe Html Msg ?
So can i write something like foo Msg ?
Like foo produces Msg?

1 Like

I think of Html Msg as an "Html document which can emit messages of type Msg".

Also, due to types being right-associative and function application being left-associative in elm, both foo and bar in your example actually have the same type.

foo : String -> String -> String is the same as foo : String -> (String -> String) and (foo "a") "b" is the same as foo "a" "b"

How do u write a function that emits ? What do u mean by emit ?

Something like "An Html document in which user actions can produce messages of type Msg"

Also some other events can cause that type of message, such as http requests, but all messages that originate from that document will have that same type.

Html Msg is a type; Html is not a function. Some types like Html have arguments that contain other types; in this case Msg is a type. Another example of a type that accepts an argument is List. For example, List Int is a list of integers.

And no, you can’t pass a type as a function argument.

3 Likes

@Pradeep Html Msg is some html where, on certain events like a button click or typing into a text box, it will send a Msg back into your application.

Elm will give that Msg to your update function, and then update the view based on the new Model.

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