In this recipe, we will look at a data type that is recursively defined. We will define a binary tree and then explore functions to traverse it.
Defining a binary tree and traversing it
Getting ready
Create a new project binary-tree-traverse using the simple Stack template. Change into this directory:
stack new binary-tree-traverse simple
How to do it...
- Open src/Main.hs; we will be using this file for our recipe.
- Define a binary tree data type:
data BinaryTree a = Leaf
| BinaryTree { left :: BinaryTree a
, val :: a
...