Whenever a type has multiple terms, it means its a generic type.
If you're familiar with Java style generics, then List Int in Elm would be Java's List<Integer>. The purpose of generics is so that we can define what a List is once, but on different instances of it the operations (like push and get) have their type signatures updated so that they accept or return different things, like Int values in our case. We didn't have to define a IntegerList and a StringList and a FooList and so on, just List a in Elm or List<T> in Java.
So similarly, Html Msg would be like Html<Msg> in Java. This is some data structure for holding HTML nodes, where some of it's operations (related to event listeners in this case) can produce values that have the type Msg. (Msg is not a special type, you defined it yourself with type Msg = Change String!).
And still similarly, Program is a generic type with 3 type parameters, so Program Flags Model Msg in Elm is like Program<Flags, Model, Msg> in Java. It's a Program that uses some type called Flags in some of it's operations that deal with program startup, some type called Model in some other operations that deal with state, and some type called Msg in other operations that deal with messaging. (Again Model and Msg are simply defined by you!)
All that's left to explain is (), which is also less special than it might first appear. It's just a type that can only have one value - () is the name of the type, and of the value. It just gets called the "unit" type, and the value is actually an empty Tuple. So operations on a Program () Model Msg can only ever get one value, the empty Tuple (), in its operations that deal with starting up - and so a Program generated by Browser.sandbox always starts up the same.
So all of this is a bit like public static void main(String[] args) in Java. As a beginner, you just write it because somebody told you to and the language demands it. Eventually you learn about when you should make things public and when static and when should they return void and how to use String[] arrays, and then you look at the boilerplate code and understand that those things really do (have to) apply to main. Same with Elm's boilerplate eventually, but don't worry too much about it as a beginner.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Whenever a type has multiple terms, it means its a generic type.
If you're familiar with Java style generics, then
List Int
in Elm would be Java'sList<Integer>
. The purpose of generics is so that we can define what a List is once, but on different instances of it the operations (likepush
andget
) have their type signatures updated so that they accept or return different things, likeInt
values in our case. We didn't have to define aIntegerList
and aStringList
and aFooList
and so on, justList a
in Elm orList<T>
in Java.So similarly,
Html Msg
would be likeHtml<Msg>
in Java. This is some data structure for holding HTML nodes, where some of it's operations (related to event listeners in this case) can produce values that have the typeMsg
. (Msg is not a special type, you defined it yourself withtype Msg = Change String
!).And still similarly, Program is a generic type with 3 type parameters, so
Program Flags Model Msg
in Elm is likeProgram<Flags, Model, Msg>
in Java. It's a Program that uses some type calledFlags
in some of it's operations that deal with program startup, some type calledModel
in some other operations that deal with state, and some type calledMsg
in other operations that deal with messaging. (AgainModel
andMsg
are simply defined by you!)All that's left to explain is
()
, which is also less special than it might first appear. It's just a type that can only have one value -()
is the name of the type, and of the value. It just gets called the "unit" type, and the value is actually an empty Tuple. So operations on aProgram () Model Msg
can only ever get one value, the empty Tuple()
, in its operations that deal with starting up - and so a Program generated byBrowser.sandbox
always starts up the same.So all of this is a bit like
public static void main(String[] args)
in Java. As a beginner, you just write it because somebody told you to and the language demands it. Eventually you learn about when you should make thingspublic
and whenstatic
and when should they returnvoid
and how to useString[]
arrays, and then you look at the boilerplate code and understand that those things really do (have to) apply tomain
. Same with Elm's boilerplate eventually, but don't worry too much about it as a beginner.