Created
October 8, 2017 01:03
-
-
Save arjkb/cc1fb94c1d5a329a93fa05152c1bf7b9 to your computer and use it in GitHub Desktop.
A simple binary-tree implementation in haskell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Tree a = Leaf a | |
| Node (Tree a) (Tree a) | |
deriving (Show, Eq) | |
treeMap :: (a -> b) -> (Tree a) -> (Tree b) | |
treeMap f (Leaf a) = Leaf (f a) | |
treeMap f (Node t1 t2) = Node (treeMap f t1) (treeMap f t2) | |
treeFold :: (b -> b -> b) -> (a -> b) -> (Tree a) -> b | |
treeFold fnode fleaf (Leaf n) = fleaf n | |
treeFold fnode fleaf (Node t1 t2) = fnode (treeFold fnode fleaf t1) (treeFold fnode fleaf t2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thank you very much for the explanation, but I am running into the following error, help.