The diamond of variance
summary
Argues that Swift's generics map onto a four-point "diamond of variance" and walks through concrete Swift code snippets showing covariance, contravariance, invariance, phantom as distinct cases. Demonstrates Optionals and closures as examples (optionals behaving like covariance, function parameters like contravariance), and shows tiny toy types where an unused generic parameter produces a phantom type. Claim: these examples expose how Swift's type system fits the theory rather than just language folklore.
AI-written summary · about
chapters (6)
- 0:00Introduction
- 0:48Understanding covariance
- 1:25Covariance in practice
- 2:20Contravariance explained
- 3:22Invariance and phantom types
- 4:21Recap and conclusion
related talks
44mType Parameter Power Up Variance Bounds and Inference
33mContravariance: intuition building from first principles
31mNothing Generic About It
49mThe Trouble With Types
11mThe Secrets of Polymorphic Variants
01h 01mConcepts vs Typeclasses vs Traits vs Protocols
41mPolymorphism Unbound
38mType Systems - The Good, Bad and Ugly
