In the previous chapter, we saw a way to group types and values together so that they can be accessed under a single namespace, and we saw how these namespaces (modules) themselves have types. Modules are not, however, convenient for passing around values during runtime. We need a lightweight way to build more structured types out of simpler types, to model real-world problems.
In this chapter, we will cover these structured types, specifically:
- Record types
- Tuple types
- Object types
- JavaScript object types
Collectively, these types are referred to as product types because the number of possible values a product type can contain is the product of the number of possible values each of its component types can contain. This is an interesting result in type theory, and it gives us a hint to the fact that types obey certain algebraic laws. I will...