The key is the word alias . In the programming process, when you want to group things that belong together, you put them in a record, for example, in the case of a period
{ x = 5, y = 4 }
or student record.
{ name = "Billy Bob", grade = 10, classof = 1998 }
Now, if you need to pass these records, you will need to specify the entire type, for example:
add : { x:Int, y:Int } -> { x:Int, y:Int } -> { x:Int, y:Int } add ab = { ax + bx, ay + by }
If you could pseudonize the point, the signature would be much easier to write!
type alias Point = { x:Int, y:Int } add : Point -> Point -> Point add ab = { ax + bx, ay + by }
So an alias is a shorthand for something else. This is an abbreviation for the record type here. You can think of it as the name of a post type that you will often use. That's why he called an alias - it's a different name for the bare record type represented by { x:Int, y:Int }
While type solves another problem. If you came from OOP, this is a problem that you solve with inheritance, operator overloading, etc. - sometimes you want to process data as a general thing, and sometimes you want to treat it as a certain thing.
A common occurrence when this happens is messaging - like a mail system. When you send an email, you want the mail system to process all messages as the same, so you only need to create the mail system once. And besides, the message routing task should be independent of the message contained inside. It is only when the letter reaches its destination that you care about what the message is.
In the same way, we could define a type as the union of all the different types of messages that can occur. Say we are introducing a messaging system between college students with parents. Thus, there are only two messages that college kids can send: "I need beer money" and "I need cowards."
type MessageHome = NeedBeerMoney | NeedUnderpants
So, when we design a routing system, the types for our functions can just go through the MessageHome , rather than worry about all the different types of messages that may be. The routing system does not care. Only MessageHome needs to know this. It is only when the message reaches its addressee, the parental home, that you need to find out what it is.
case message of NeedBeerMoney -> sayNo() NeedUnderpants -> sendUnderpants(3)
If you know the Elm architecture, the update function is a gigantic case argument because it is the destination where the message is routed and therefore processed. And we use union types to have one type that we have to deal with when sending a message, but then he can use the case statement to tease exactly what it was, so we can deal with it.