Trying to learn Elm with experience in JS and little experience in languages with strong and static types, I found that the main difficulty is with the type syntax (and which types are useful for Elm in general). Unfortunately, I do not find the documents very useful in this regard.
If I take a simple example here: http://elm-lang.org/examples/buttons , line:
type Msg = Increment | Decrement
defines the type of association Msgas being either Incrementor Decrement. It seems that Incrementand Decrementare also types. What it is? (They are not defined elsewhere in this example and are not predefined types).
They are then used in the function viewas an argument onClick. Now they seem to act as a kind of “message” (whatever that means). In JS, this is likely to be achieved by assigning a value to a variable (mutable) in each case, which, of course, cannot be the Elm way. So, is the way types work with the topic of immutability?
Function view:
view model =
div []
[ button [ onClick Decrement ] [ text "-" ]
, div [] [ text (toString model) ]
, button [ onClick Increment ] [ text "+" ]
]
I think this potentially opens up a broader topic (if someone can point out useful links, thanks!), But my question is: what is here Incrementand Decrementhere? How do they fit into a system like Elm?
source
share