~/talk

GET MORE CLARITY WITH OPAQUE TYPES IN SCALA 3

Talkat Scalar Conference 2023 · 2023-03-23..03-24· [scala]
slides:none on file

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

  1. 0:00Introduction
  2. 0:28Define the problem
  3. 1:54Types in Scala 2
  4. 3:24Example
  5. 9:15Smart Constructor
  6. 14:50Legacy Method
  7. 17:40Summary
  8. 19:11Questions
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.