GET MORE CLARITY WITH OPAQUE TYPES IN SCALA 3
summary
Scala 3’s opaque type aliases provide a middle ground between raw primitives and wrappers: an opaque type alias is treated as the underlying type inside its defining scope but is hidden elsewhere, so plain ints can’t be accidentally passed as Pages or Year. The demo builds object-level smart constructors returning Option, adds instance behavior with extension methods, and shows the subtype trick to inherit Int’s API; runtime is erased with no runtime overhead. Drawbacks shown: no default constructors, no pattern matching, and equals/toString cannot be overridden.
AI-written summary · about
chapters (8)
- 0:00Introduction
- 0:28Define the problem
- 1:54Types in Scala 2
- 3:24Example
- 9:15Smart Constructor
- 14:50Legacy Method
- 17:40Summary
- 19:11Questions
related talks
32mAdvanced Features of Scala 3
30mLessons Learned from 15 Years of Scala in the Wild
45mHow to be polymorphic in Scala
49mOOP versus Type Classes in Scala
43mA Tour of Contextual Abstractions in Scala 3
35mIntroducing Typelevel Scala into an OO environment
48mObject Functional Programming
51mOpening Keynote: New Functional Constructs in Scala 3
