TYPECLASSES — A TYPE SYSTEM CONSTRUCT
summary
Typeclasses provide ad hoc polymorphism in Scala but are implemented via implicits, which creates surprises: orphan instances roam globally, implicit search picks the most specific available and can cause ambiguity, and overlapping instances break coherence and move-code semantics. Lessons from Haskell and Rust lead to concrete fixes: put instances in companion objects or a dedicated orphan package, use wrapper types for alternative semantics, and use Simulacrum/Cats (macros that generate ops and syntax) to reduce boilerplate and improve discoverability.
AI-written summary · about
chapters (15)
- 0:00Introduction
- 1:24Supporthoc polymorphism
- 4:08Defining the type class
- 7:50Type class definition
- 12:17Type class implementation
- 12:38Orphan instances
- 14:17Rust
- 16:20Implicit Resolution
- 17:47Issues with Type
- 23:26Simulacrum
- 27:04Cat
- 28:20Orphans
- 28:43OK
- 29:40Maintainability Readability
- 29:59Summary
related talks
43mDon't Fear the Implicits: Everything You Need to Know About Typeclasses
31mType-Classes (in Scala 3)
45mHow to be polymorphic in Scala
20mType Classes for the Rest of Us
58mSeparating Behavior and Data with Type Classes in Scala
41mPolymorphism in Scala
49mOOP versus Type Classes in Scala
49mAcademese to English: Scala's Type System, Dependent Types and What It Means To You
