Written 2021-10-06

Union types and sum types are programming language concepts that have been around for decades, but I think they're getting more popular these years. The two concepts are closely related but their subtle differences impacts their relative strengths. This post is an explanation of the concepts and a list of pros and cons of the two.

Union types, sum types and product types are all algebraic data types, which sound super complicated, but the basic concept is actually really simple.

Let's begin somewhere familiar: With an ordinary struct. A database used by my job contains "cases" who are known by identifiers like this