Algebraic Data Types
ELI5 — The Vibe Check
Algebraic data types are like Lego for type systems. You can build types by combining them — 'this AND that' (product types like tuples) or 'this OR that' (sum types like enums). It's math meets programming, and it's surprisingly practical.
Real Talk
A type system concept from functional programming where composite types are formed by combining other types using two operations: product types (AND — structs, tuples, records) and sum types (OR — tagged unions, enums). ADTs enable precise modeling of domain concepts and exhaustive pattern matching.
When You'll Hear This
"Algebraic data types let you model your domain so precisely that invalid states are unrepresentable." / "Rust's enum is a sum type — it's one of the language's killer features."
Related Terms
Discriminated Union
A discriminated union is like a box that could contain a cat, a dog, or a fish — but it has a label on the outside telling you which one.
Pattern Matching
Pattern matching is like a super-powered switch statement that can look inside data structures and pull out the parts you need.
Product Type
A product type is 'this thing has a name AND an age AND an email — all at once.' It's your everyday struct or object.
Sum Type
A sum type is 'this thing is EITHER a cat OR a dog OR a fish — pick one.' It's like a multiple choice question for types.