P
Size: a a a
P
P
V
P
NK
AE
AE
BB
SS
AE
SS
data Tree1 a = Nil | Node1 a (Tree1 a) (Tree1 a)
data Tree2 a b = Leaf2 b | Node2 a b (Tree2 a b) (Tree2 a b)
data Tree3 = Leaf3 String | Node3 String Tree3 Tree3
type Lst a = [a]
data Rope a b = Nil | Twisted b (Rope b a)
class Size a where
size :: a -> Int
instance Size (Tree1 a) where
size Nil = 0
size (Node1 _ l r) = 1 + size l + size r
instance Size (Tree2 a b) where
size (Leaf2 _) = 1
size (Node2 _ _ l r) = 2 + size l + size r
instance Size Tree3 where
size (Leaf3 m) = length m
size (Node3 m l r) = length m + size l + size r
instance Size [a] where
size = length
instance Size (Rope a b) where
size Nil = 0
size (Twisted _ ls) = 1 + size ls
AE
SS
S
S
YK
YK
YK
AE
YK