--- /dev/null
+Zij gegeven:\r
+\r
+:: BTree a = Tip a | Bin (BTree a) (BTree a)\r
+\r
+map :: (a -> b) [a] -> [b]\r
+map f [] = [] (1.)\r
+map f [x:xs] = [f x : map f xs] (2.)\r
+\r
+mapbtree :: (a -> b) (BTree a) -> BTree b\r
+mapbtree f (Tip a) = Tip (f a) (3.)\r
+mapbtree f (Bin t1 t2) = Bin (mapbtree f t1) (mapbtree f t2) (4.)\r
+\r
+foldbtree :: (a a -> a) (BTree a) -> a\r
+foldbtree f (Tip x) = x (5.)\r
+foldbtree f (Bin t1 t2) = f (foldbtree f t1) (foldbtree f t2) (6.)\r
+\r
+tips :: (BTree a) -> [a]\r
+tips t = foldbtree (++) (mapbtree unit t) (7.)\r
+\r
+unit :: a -> [a]\r
+unit x = [x] (8.)\r
+\r
+\r
+Te bewijzen:\r
+ voor alle functies f, voor alle eindige bomen t:\r
+ \r
+ map f (tips t) = tips (mapbtree f t)\r
+\r
+Bewijs:\r
--- /dev/null
+implementation module BinSearchTree\r
+\r
+import StdEnv\r
+import BinTree\r
+\r
+z0 = Leaf\r
+z1 = insertTree 50 z0\r
+z2 = insertTree 10 z1\r
+z3 = insertTree 75 z2\r
+z4 = insertTree 80 z3\r
+z5 = insertTree 77 z4\r
+z6 = insertTree 10 z5\r
+z7 = insertTree 75 z6\r
+z8 = deleteTree 50 z7\r
+\r
+// Uit het diktaat, blz. 73:\r
+insertTree :: a (Tree a) -> Tree a | Ord a\r
+insertTree e Leaf = Node e Leaf Leaf\r
+insertTree e (Node x le ri)\r
+| e <= x = Node x (insertTree e le) ri\r
+| e > x = Node x le (insertTree e ri)\r
+\r
+deleteTree :: a (Tree a) -> (Tree a) | Eq, Ord a\r
+deleteTree e Leaf = Leaf\r
+deleteTree e (Node x le ri)\r
+| e < x = Node x (deleteTree e le) ri\r
+| e == x = join le ri\r
+| e > x = Node x le (deleteTree e ri)\r
+where\r
+ join :: (Tree a) (Tree a) -> (Tree a)\r
+ join Leaf b2 = b2\r
+ join b1 b2 = Node x b1` b2\r
+ where\r
+ (x,b1`) = largest b1\r
+ \r
+ largest :: (Tree a) -> (a,(Tree a))\r
+ largest (Node x b1 Leaf) = (x,b1)\r
+ largest (Node x b1 b2) = (y,Node x b1 b2`)\r
+ where\r
+ (y,b2`) = largest b2\r
+\r
+\r
+is_geordend :: // meest algemene type\r
+is_geordend ...\r
+\r
+Start = map is_geordend [t0,t1,t2,t3,t4,t5,t6,t7]\r
+\r
+\r
+is_gebalanceerd :: // meest algemene type\r
+is_gebalanceerd ...\r
+\r
+//Start = map is_gebalanceerd [t0,t1,t2,t3,t4,t5,t6,t7]\r