Type Parameter Power Up Variance Bounds and Inference
summary
A practical walk through why Scala’s variance rules matter: a real system uses a free monad workflow and hits the error covariant type A occurs in contravariant position when wrappers and keeper-like APIs mix +/− annotations with method args and returns. Examples show invariant/covariant/contravariant wrappers, why prepending widens List[Int] to List[Any] via lower/upper bounds, and how context bounds introduce implicit evidence parameters to enable type class derivation. Compiler messages are often unhelpful but Scala 3 keeps the same semantics.
AI-written summary · about
chapters (12)
- 0:00Start
- 1:21Why Should Users and any Api Designers Learn about these Kinds of Topics
- 2:42Overview
- 3:03Inheritance and Substitution
- 4:06Liskov Substitution Principle
- 12:20Contravariant Wrapper
- 14:07Contravariance
- 28:49Constraints and Type Classes
- 30:26Bounds and Variants
- 33:32View Bounds
- 33:56Context Bounds
- 34:49Psych Class Pattern
related talks
33mContravariance: intuition building from first principles
28mSecrets of the Scala Type System
05mThe diamond of variance
42mLet the Compiler Help You: How to Make the Most of Scala's Type System
44mType level Computations in Scala
48mA gentle introduction to type level programming in Scala
49mThe Trouble With Types
44mTelling the Truth with Types
