diff options
Diffstat (limited to 'lec04/hw.hs')
-rw-r--r-- | lec04/hw.hs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lec04/hw.hs b/lec04/hw.hs index bb5a026..923ec01 100644 --- a/lec04/hw.hs +++ b/lec04/hw.hs @@ -37,3 +37,14 @@ treeInsertBalanced t@(Node h tl@(Node hl _ _ _) e tr@(Node hr _ _ _)) a foldTree :: [a] -> Tree a foldTree = foldr (flip treeInsertBalanced) Leaf + +-- Exercise 3 + +xor :: [Bool] -> Bool +xor = odd . foldl (\s x -> if x then s+1 else s) 0 + +map' :: (a -> b) -> [a] -> [b] +map' f = foldr (\x s -> f x : s) [] + +myFoldl :: (a -> b -> a) -> a -> [b] -> a +myFoldl f base xs = foldr (flip f) base (reverse xs) |