CHAPTER 4

image

Using Containers and Type Classes

You have seen how parametric polymorphism and higher-order functions help in the process of abstraction. In this chapter, I’ll introduce a new kind of polymorphism that sits in between parametric and the absence of polymorphism: ad hoc polymorphism. Using this feature, you can express that certain types exhibit a common behavior. And incidentally, you will learn how Haskell makes it possible to use addition, (+), on different numeric types while maintaining a strong type system.

Containers will be used in the examples throughout this chapter. A container is any data structure whose purpose is to hold ...

Get Beginning Haskell: A Project-Based Approach 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.