Ver Fonte

Merge branch 'exo'

Exercices on recursive types.
Exercices with list and binary tree.
DricomDragon há 5 anos atrás
pai
commit
640f9c9434
2 ficheiros alterados com 12 adições e 0 exclusões
  1. 6 0
      list.hs
  2. 6 0
      tree.hs

+ 6 - 0
list.hs

@@ -0,0 +1,6 @@
+data List = Ground | Leaf Integer List
+
+hyperSum xs = case xs of
+	Ground -> 0
+	Leaf x tail -> x + hyperSum tail
+

+ 6 - 0
tree.hs

@@ -0,0 +1,6 @@
+data BinaryTree = Leaf | Node Integer BinaryTree BinaryTree
+
+height bigTree = case bigTree of
+	Leaf -> 0
+	Node _ leftTree rightTree -> 1 + max (height leftTree) (height rightTree)
+