Polymorphism in Scala
summary
Compares four polymorphism techniques in Scala—subtyping, generics (parametric polymorphism), implicits/typeclasses, and ad hoc pattern-based dispatch—by implementing a reusable Printer typeclass using implicits and companion-object instance discovery. Shows how the Scala compiler selects implementations, how variance and higher-kinded type parameters affect APIs, which approaches require boilerplate, and when instance forwarding or default instances reduce code; includes small runnable examples and a few failure cases that reveal surprising loss of type information.
AI-written summary · about
chapters (12)
- 0:00Polymorphism in Scala
- 4:18Function parameter inclusion
- 8:31Parameter combinations
- 13:19Firewall details
- 16:33Variance in containers
- 20:54Modifying classes
- 24:09Interface design
- 27:51Object lifecycle
- 30:56Parameter context
- 34:45External interfaces
- 37:51Boilerplate
- 40:57Summary
related talks
45mHow to be polymorphic in Scala
43mAdding kind-polymorphism to the Scala programming language
42mPolymorphic Function Types in Scala 3
51mAdding Kind-polymorphism To The Scala Programming Language
32mUnderstanding the Type System of Scala 3
31mTYPECLASSES — A TYPE SYSTEM CONSTRUCT
40mPolymorphic Function Types in Scala 3
45mDesign Patterns in Scala
