Skip to content

Algebraic Data Types

Complex types can be built from simpler types through composition (product types - AND) and alternation (sum types - OR), enabling precise modeling of domain concepts where values can be "this AND that" or "this OR that."

Tension Addressed

Expressiveness vs. Simplicity

Recognizable As

Structs/records (product types); enums with associated data, tagged unions, "Either" types (sum types); pattern matching to destructure values; exhaustiveness checking by compiler

Canonical Sources

Pierce, Types and Programming Languages (2002); Wadler, "The Expression Problem" (1998)

Transfers To

Data modeling in any domain, protocol design (message types as sum types), state machines (states as sum types)

Product types let you say "a Person has a name AND an age." Sum types let you say "a Result is either Success OR Failure." Together, they enable precise domain modeling that makes illegal states unrepresentable. Pattern matching provides safe destructuring with exhaustiveness guarantees.