Now that we've seen the product and sum types in action, let's take a step back and ask how they can work together. Intuitively, product types let us group values together, and sum types let us choose one among a restricted set of values. Together, they express a wide range of data modeling scenarios. Let's look at a couple of examples.
Designing for correctness with types
Products and sums together
First, a simple example to warm up. Suppose we're asked to track the following attributes of a person for a Customer Relationship Management software:
- ID number: A string
- Name: A string
- Education level: One of school, college, postgrad, or other
A valid person record must have all of these attributes. Notice...