July 2023
Intermediate to advanced
670 pages
17h 13m
English
Before we dive into using type classes, let’s take a look at a small motivating example. Imagine that we wanted to write a function that could remove duplicate elements from a list. If we’re only making use of parametric polymorphism we’re a little bit limited in how we can write a function like this. To remove duplicates from the list we need to compare elements to find out if they match. The problem here is that our elements could be anything. We might even be dealing with functions or some other value that doesn’t have a regular notion of equality.
Your first thought might be to just use the (==) function that we’ve been making use of throughout this book, but as you’ll see shortly, the (==) function ...
Read now
Unlock full access