foldTree = foldr f Leaf
where f x acc = insert x acc
-
+-- exercise 3
+-- xor
+xor :: [Bool] -> Bool
+xor bs = foldr f False bs
+ where f False False = False
+ f False True = True
+ f True False = True
+ f True True = False
+
+-- implement map as a fold
+map' :: (a -> b) -> [a] -> [b]
+map' f = foldr f' []
+ where f' x acc = (f x) : acc