Data Types Are Cheap

As I said at the outset (and will say again), all we did here was to identify the kinds of data we had in the problem domain, and what kinds of transformations we wanted to perform on it, and then we built up the data structures and the code to do the transformations.

Let’s look at the tools that modern functional languages provide for doing this.

The first “tool” is the sheer flexibility for declaring new data types and the scope for reusing them. This is very important: rather than encoding some data in a hash and hoping that you remember to keep the encoding consistent, Haskell allows—even encourages—you to add a new type that expresses exactly what you want to store. Such type declarations are much shorter than the ...

Get Functional Programming: A PragPub Anthology 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.