O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

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

How it works...

  1. The binary tree can either be empty (no value, no children) or can have exactly two child trees and a value. 
  2. The binary tree is parameterized by a type argument. The type argument denotes the type of the value that each node stores.
  1. The binary tree is defined as a sum type. Following are the alternatives for the sum type:
    1. The empty tree is denoted by data constructor Leaf.
    2. The binary tree node is a product type (BinaryTree) implemented using record syntax, with the following fields:
      • left: This denotes the left binary tree
      • val: This indicates the value of the node
      • right: This denotes the right binary tree
    3. Since left and right  are of type BinaryTree, this is a recursively defined data type.
  2. The helper function empty ...

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