Type Parameter Power-Up! Variance, Bounds, and Inference
summary
A practical tour of Scala variance and bounds shows when the compiler refuses code (example error covariant type A occurs in contravariant position) and how to fix it: use lower bounds like B >: A to implement a covariant prepend, prefer context bounds and implicits to supply evidence, and implement reusable patterns as a type class (example adder type class for Int and Pair). Examples compile on Scala 2 and stay valid under Scala 3 / Dotty.
AI-written summary · about
chapters (11)
- 0:00Start
- 1:47Motivations
- 4:34Liskov Substitution Principle
- 5:13Generic Classes
- 7:46When Can We Substitute Which Kinds of Machines
- 8:26Types of Variants
- 10:48Covariance
- 24:51Upper or Lower Bound
- 28:53Context Bounds
- 30:20Type Class Pattern
- 34:59Structural Types
related talks
45mHow to be polymorphic in Scala
32mUnderstanding the Type System of Scala 3
45mScala 3, Type Inference and You!
48mAcademese to English: A Practical Tour of Scala’s Type System
45mTypelevel Programming 101: The Subspace of Scala
30mDotty and types: the story so far
42mPolymorphic Function Types in Scala 3
49mType level Programming in Scala
