Generics
- Type parameters. Generics parameterise classes and methods: Box[A], checked at compile time, erased at runtime.
- Context bounds. A context bound: [A: Ordering]: demands a capability alongside the type.
- Higher-kinded awareness. Higher-kinded types abstract over containers: F[_]: the shape libraries like effect systems build on.
Variance
- Covariance. +A marks covariance: a List of Cats is a List of Animals, safely, because Lists only produce.
- Contravariance. -A marks contravariance: a handler of Animals handles Cats: consumers flip the arrow.
- Variance in APIs. Variance annotations are API promises: the compiler rejects designs that would lie.
Type Bounds and Advanced Types
- Bounds. Upper and lower bounds: A <: Animal: relate type parameters to hierarchies.
- Opaque types. opaque types wrap primitives at zero cost: UserId that cannot be confused with String.
- Union and intersection types. Scala 3 adds union (A | B) and intersection (A & B) types: precise signatures without wrappers.
Before and after this level
- Before: Level 5: Functional Programming: Higher-Order Functions, Pure Functions and Immutability, Function Composition.
- Next: Level 7: Scala 3 Features: Givens and Contextual Abstractions, Extension Methods, Modern Scala Design.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Scala Level 6: Type System cover?
Generics, Variance, Type Bounds and Advanced Types: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 5: Functional Programming, which covers Higher-Order Functions, Pure Functions and Immutability, Function Composition.