Lesson 13. Type classes

After reading lesson 13, you’ll be able to

  • Understand the basics of type classes
  • Read type class definitions
  • Use common type classes: Num, Show, Eq, Ord, and Bounded

In this lesson, you’re going to look an important abstraction in Haskell’s type system: type classes. Type classes allow you to group types based on shared behavior. At first glance, type classes are similar to interfaces in most object-oriented programming languages. A type class states which functions a type must support in the same way that an interface specifies which methods a class must support. But type classes play a much more important role in Haskell than interfaces do in languages such as Java and C#. The major difference is that as you dive ...

Get Get Programming with Haskell now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.