Skip to content
Latchkey

What Is a Sum Type?

A sum type, also called a tagged union or variant, is a type whose value is one of a fixed set of alternatives, with a tag identifying which one. Each alternative can carry its own kind of data. The number of possible values is the sum of the possibilities of its variants, which is where the name comes from.

Why it matters

Sum types model "one of these cases" precisely and force code to consider every case, often checked by exhaustiveness analysis. They eliminate whole classes of bugs caused by representing alternatives with loosely related flags.

Related guides

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