The previous chapter gave you solid foundations to move with agility among Scala's type system. This chapter starts by introducing an advanced type system concept that goes by the name of higher-kinded types.
It proceeds with an overview of the most common functional design patterns, such as functor, applicative and monad. As you'll see, these concepts are much easier than you might think.
The chapter ends with an analysis of two very simple algebraic structures, showing how they can be exploited to write very elegant code.
Option or List are not proper types, but they are kinds. A kind is the type of a type constructor. Simply speaking, it means that, in order to be constructed, it needs another type.
In type theory, kinds like
Option are indicated using the following symbology:
* -> *. The star symbol stands for type. So,
* -> * means: “Give me a type and I construct another type.” Indeed, given the
List kind, if you provide the
Int type then your final type will be
List[Int]. If you furnish a
String then it'll be a
List[String] and so on. Table 10.1 shows the most commonly used kinds.
Table 10.1 Kinds in Type Theory
|*||Simple type. Also known as nullary type constructor or proper ...|