2

Algebraic Datatypes

While functions are, of course, central in functional programming, they have to have values to process. Haskell classifies values by means of types and provides a number of built-in types such as Integer and Bool. Yet, these integer types are rather limited and rather generic. For this reason, Haskell provides a facility for defining user-defined datatypes, called algebraic datatypes.

This chapter explains how algebraic datatypes work. We first study two simple forms of algebraic datatypes (enumerations and records) that have well-known counterparts in other programming languages. Then, we merge the two features into the full-blown form of algebraic datatypes. We learn about the different elements of an algebraic datatype ...

Get Soar 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.