Creating Inductively Defined Data Structures

Data types in Haskell are also how we express data structures. Thanks to laziness, writing data structures in Haskell can present some interesting opportunities for thinking about new ways to express the structures of data. Most data structures that you’ll build in Haskell are recursive, or as we sometimes call them, inductively defined. In this section, you’ll implement several different inductively defined data structures.

Counting With Peano Numbers

The simplest type of inductively defined data structure that you can implement is a type that represents a peano number. Peano numbers are a way of representing whole numbers as a recursive function, where a given peano number is either “zero” or “a ...

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