Skip to content
Latchkey

What Is an Algebraic Data Type?

An algebraic data type is a composite type built by combining other types as products, which group several values together, and sums, which offer a choice among several alternatives. A value of a sum type is exactly one of its variants, each of which may carry its own data. This lets you precisely model data that can take one of several shapes.

Why it matters

Algebraic data types make invalid states unrepresentable by encoding the exact set of possibilities a value can take. They pair with pattern matching to handle each variant explicitly and safely.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →