module Expression where
data Expression a
= Number a
| Node (Expression a)
Operand
(Expression a)
deriving (Show, Eq)
data Operand
= Plus
| Minus
| Times
| DividedBy
| Power
deriving (Show, Eq)
eval :: Floating a => Expression a -> Expression a
eval = undefined — TODO
module RoseTree where
data RoseTree a =
RoseNode a
[RoseTree a]
deriving (Show, Eq)
treeSize :: Integral b => RoseTree a -> b
treeSize = undefined — TODO
treeDepth :: Integral b => RoseTree a -> b
treeDepth = undefined — TODO
treeLeaves :: RoseTree a -> [a]
treeLeaves = undefined — TODO
module BinarySearchTree where
import BinaryTree
type BinarySearchTree a = BinaryTree a
treeIsValid :: Ord a => BinarySearchTree a -> Bool
treeIsValid = undefined — TODO
treeMinimum :: BinarySearchTree a -> a
treeMinimum = undefined — TODO
treeMaximum :: BinarySearchTree a -> a
treeMaximum = undefined — TODO
treeContains :: Ord a => a -> BinarySearchTree a -> Bool
treeContains = undefined — TODO
treeFlattenOrdered :: BinarySearchTree a -> [a]
treeFlattenOrdered = undefined — TODO
treeInsert :: Ord a => a -> BinarySearchTree a -> BinarySearchTree a
treeInsert = undefined — TODO
module BinaryTree where
data List a
= Empty
| Cons a
(List a)
deriving (Show, Eq)
data BinaryTree a
= Null
| Node a
(BinaryTree a)
(BinaryTree a)
deriving (Show, Eq)
tree1 :: BinaryTree Int
tree1 =
Node
5
(Node
4
(Node 2 Null (Node 11 Null Null))
(Node 1 (Node 0 Null Null) (Node (-3) Null Null)))
(Node 3 (Node 8 (Node (-4) Null Null) (Node 7 Null Null)) Null)
— Exercise 1
treeSize :: Integral b => BinaryTree a -> b
treeSize = undefined — TODO
treeDepth :: Integral b => BinaryTree a -> b
treeDepth = undefined — TODO
treeFlatten :: BinaryTree a -> [a]
treeFlatten = undefined — TODO
treeLeaves :: BinaryTree a -> [a]
treeLeaves = undefined — TODO
— Exercise 2
treeMap :: (a -> b) -> BinaryTree a -> BinaryTree b
treeMap = undefined — TODO