Writing extensible functional code
summary
Shows using protocols/typeclasses (Elixir/Clojure/Haskell-style) to recover data-oriented extensibility: protocols/typeclasses dispatch on the first argument so implementations can live outside original modules. Uses a concrete geometry example (Point, Line, Nothing, Segment) to demonstrate the classic trade: adding a new shape forces edits to plain functions but adding a new operation forces edits to every type. With protocols the code can add new data without editing existing functions and add new operations without touching data types, but warns against blanket protocol use—it's a tradeoff.
AI-written summary · about
chapters (10)
- 0:00Start
- 3:23Comprehensibility
- 6:25Accessibility
- 11:18Object-Oriented Solution
- 12:21Double Dispatch
- 14:10Compute the Length of a Geometric Shape
- 16:53Protocols
- 25:42Open Closed Principle
- 26:24The Interface Segregation Principle
- 27:27Conclusion
related talks
24mTypeclasses: the value of programming vocabulary
47mThe many shapes of Polymorphism
41mEvolving Functional Programming Languages
48mAncestry of Polymorphism in Clojure
36mPoint-Free or Die: Tacit Programming in Haskell and Beyond
42mProgramming with Math
42mFunctional Programming in 40 Minutes
49mFunctional Programming Essentials
