July 2023
Intermediate to advanced
670 pages
17h 13m
English
You’ve seen how type classes allow you to create abstractions in your programs. A problem with type classes that you might have already run into is that most of the time you’re doing a lot of work to create instances, but the code is uninteresting and often redundant. As an example, let’s imagine a simple record to hold some customer info:
| | data Customer = Customer |
| | { name :: String |
| | , mail :: String |
| | , email :: String |
| | } |
For our application, we’d like to provide implementations for three common type classes, Show, which will allow us to convert a customer record to a string, Eq, which will let us test equality between two records, and Ord, which will allow us to sort our records. We can manually implement ...
Read now
Unlock full access