The type system

The type system is the part of Scala that carries the most weight in a large program. A type parameter says that a container works for any element, a variance annotation says whether a container of a subtype is a container of the supertype, and a bound says what a type parameter must be able to do. A union type says one of two things, an intersection type says both at once.

The second half of the part is about capabilities a method asks for without naming them: a given instance the compiler supplies, the type class pattern built on it, the extension method that adds a member to a type, and the inline and match types that let the compiler compute code and types from what it is given. derives is the last step: one word that asks for an instance the compiler can build.

049 Generics a type parameter on a class and on a method, and the inference that fills it in Open 050 Variance and bounds covariance, contravariance, upper and lower bounds, and why Array is invariant Open 051 Union and intersection types A | B in a parameter, A & B for a value that is both, and the match they allow Open 052 given and using a given instance, a using parameter, the anonymous given and the import that brings it in Open 053 Type classes the pattern behind Ordering and Show, a given instance, and a context bound Open 054 Extension methods extension, the receiver, a generic extension, and the import it needs Open 055 Match types and inline inline, compiletime.constValue, a match type, and the error an unmatched type gives Open 056 Derives a type class written by hand, the same one derived, and what derives writes Open

Lessons