Lesson 14. Using type classes

After reading lesson 14, you’ll be able to

  • Implement your own type classes
  • Understand polymorphism in Haskell
  • Know when to use deriving
  • Search for documentation with Hackage and Hoogle

In lesson 13, you got your first look at type classes, which are Haskell’s way of grouping types by common behaviors they share. In this lesson, you’ll take a deeper look at how to implement existing type classes. This will allow you to write new types that take advantage of a wide range of existing functions.

Consider this

You have a data type consisting of data constructors for New England states:

data NewEngland = ME | VT | NH | MA | RI | CT

You want to be able to display them by their full name by using Show. You ...

Get Get Programming with Haskell 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.