O'Reilly logo

The Haskell School of Expression by Paul Hudak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER SEVEN

Trees

 

 

 

 

 

We have so far only scratched the surface of the many kinds of useful data types that can be created in Haskell. In this chapter I will introduce the use of recursive and tree-shaped data types. In the process we will look at a few motivating examples of trees, but will use them more concretely in the next chapter when we create a data type of geometric regions.

7.1 A Tree Data Type

In Chapter 2 we defined a data type called Shape:

images

Note that every value created of this type has the same relative size, except that the list of vertices in a polygon can be arbitrarily long. In fact, lists are an example of a data type ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required