Some practical examples of type classes


Details
Type classes are functional programming’s way of defining new classes based on another type, whereas inheritance is object-oriented programming’s way of defining new classes based on another type. Scala allows us to use either method, so what’s the difference in practical terms? When would you use one and not the other?
We will illustrate the type class concept with a simple example: Comparer[T], a more functional way of performing three-way compares than the Java mechanism. Then we will look at a much more complex use of type classes in TableParser, a utility for reading CSV files and suchlike. As with the mechanism for parsing JSON, for instance, we will find that the compiler can not only be used to parse our code and generate byte code, but it can also be coopted to write repetitive code for us!
Robin Hillyard has been programming for over 50 years, the last seven of which have been mostly in Scala. He’s an Associate Teaching Professor in the College of Engineering at Northeastern University and has been teaching a class on Scala and Big Data for four years (about 200 students in total). He also teaches a class on Data Structures and Algorithms. Over the years, he’s worked in a number of different companies spanning pretty much all industries. Many of these have been software companies and he’s held all the different jobs at one time or another. Currently, he’s working on a paper describing a faster way of sorting objects that involve complex comparisons.
This month's meeting is being hosted and sponsored by Hopper: https://www.hopper.com/

Some practical examples of type classes