-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Soar with Haskell
By :

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 definition: the type name, the data constructors, and their fields. We see how algebraic datatype values are created and how they are taken apart by pattern matching. Finally, we see how both functions and algebraic datatypes can be parameterized...