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 built-in 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access