Browse Source

Merge branch 'exo'

Exercices on recursive types.
Exercices with list and binary tree.
DricomDragon 5 năm trước cách đây
mục cha
commit
640f9c9434
2 tập tin đã thay đổi với 12 bổ sung0 xóa
  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)
+