O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with type classes

In this recipe, you will learn about type classes. The type classes provide a common behavior across data types. In this way, a type class abstracts the common behavior and can be implemented by a variety of data. One can relate type classes to interface in C# or C++. 

So far, whenever we defined data types we derived the data types from the Show type class without providing any explicit implementation for the type. In such cases, the default implementation is provided by GHC. In this recipe, we will provide explicit implementation for the standard Haskell type classes Show, Read, Enum, Eq, and Ord.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required