Ad Hoc Polymorphism and Type Classes
In this section, we'll be exploring ad hoc polymorphism, but through the usage of type classes.
Types of Polymorphism
In computer science, polymorphism is the provision of a single interface to entities of different types. Polymorphism consists of three types: subtyping, parametric polymorphism, and ad hoc polymorphism.
Subtyping enables polymorphism by having different implementations of the same method (but keeping the interface) in the different subclasses. Parametric polymorphism enables polymorphism by allowing code to be written without the mention of a specific type. For example, when you operate over a generic
List
, you're applying parametric polymorphism. Ad hoc polymorphism enables polymorphism by allowing ...
Get Professional Scala now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.