Keep Your Types Small
summary
Walks through the validator code from a Medium article and shows concrete design choices that shrink program space by counting type cardinalities, turning a search from about 10^16 to 283 possible validators. Uses Scala algebraic data types, enums, generics, type classes and libraries like Cats and SyncIO, plus optics and recursion schemes, to argue for smaller domain types, fewer sums in parameter position, and how parametric polymorphism can make many functions unique.
AI-written summary · about
chapters (14)
- 0:00Introduction to small types
- 2:50Measuring type size
- 5:48Algebraic data types explained
- 8:22Shrinking program cardinality
- 10:31Prefer enums over classes
- 12:18Avoid sums in parameters
- 15:30Tools for cardinality analysis
- 16:56Generics reduce complexity
- 18:23Reusing common algebras
- 20:07Domain types shrinking
- 21:32Avoid general parameters
- 22:13Property-based testing benefits
- 22:35Optics and recursion schemes
- 23:16References and conclusion
