- Create a new Haskell project binary-tree-functor using the simple Stack template:
stack new binary-tree-functor simple
- Open src/Main.hs. This is the file that will be used for our purposes.
- After adding module definition for Main, add the following import:
module Main where import Data.Functor
- Define the binary tree and utility functions to create the tree:
-- The tree can be empty (Leaf) or a node with a -- value, left and right trees. data Tree a = Leaf | Node (Tree a) a (Tree a) deriving (Show, Eq)
-- Create a tree given a value, left tree and a right tree node :: Tree a -> a -> Tree a -> Tree a node l x r = Node l x r
-- Induct a value into a new tree (node with empty left and right trees) singleton :: a ...