2 Type classes

This chapter covers

  • Exploiting type classes as tools for writing code that works for values of different types
  • Considering type classes as a concept applicable to many types
  • Using basic type classes defined in the standard library
  • Abstracting computations via type classes

Haskell programmers tend to write code that can be reused in many ways. To achieve that, they avoid using specific types while writing code and use type variables instead. Depending on the types, the actual code may differ. This is possible thanks to type classes and their instances.

Type classes are usually considered Haskell’s most prominent feature. They originated in Haskell and were then taken up by other programming languages. A type class is defined ...

Get Haskell in Depth 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.