Far More Than You’ve Ever Wanted To Know About Adts
summary
Starts from a buggy int-based Direction enum, shows why Scala's built-in enumerations disable pattern-match exhaustivity, implements hand-rolled sealed ADTs, and builds a recursive Command type with Chain to compose actions. Then adds phantom types Idle/Moving and turns Command into a GADT that encodes before/after states, so the compiler forbids invalid sequences (e.g., start when already moving). Demonstrates algebraic reasoning (list size n has |A|^n possibilities, Boolean lists ≤2 produce 7 values) and shows the implementation compiles and enforces safety.
AI-written summary · about
chapters (19)
- 0:00Introduction to data modeling
- 1:50Why Gundams and examples
- 4:16Early mistakes with directions
- 6:46Problems with Scala enumerations
- 8:52Sealed types for safety
- 11:39Key takeaways so far
- 12:23Case classes and commands
- 15:53Defining algebraic data types
- 19:25Sum types and product types
- 23:37Scala 3 enums and ADTs
- 25:23Command composition issues
- 26:27State transitions with types
- 30:19Generalized algebraic data types
- 31:21Defining GADTs
- 33:50Why call them algebraic data types
- 36:19Cardinality and isomorphisms
- 42:00Recursive data types
- 45:30Algebraic properties of ADTs
- 46:12Summary and closing
