May 2021
Intermediate to advanced
553 pages
13h 45m
English
Content preview from Programming Scala, 3rd Edition
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
Start your free trial



Chapter 17. Scala’s Type System, Part II
This chapter continues the type system survey that we started in the previous chapter, covering more advanced constructs. You can skip this chapter until you need to understand the concepts discussed here.
Let’s begin with match types and the broad subject of dependent typing.
Match Types
Scala 3 extends pattern matching to work at the type level for match types. Let’s look at an example adapted from the Scala documentation. The following match type definition returns a type that is the type parameter of another type with one type parameter. For example, for Seq[Int] it will return Int:
// src/script/scala/progscala3/typesystem/matchtypes/MatchTypes.scalatypeElem[X]=XmatchcaseString=>CharcaseIterableOnce[t]=>tcaseArray[t]=>tcase?=>X