projects
/
yorgey.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
7bc00f7
)
hw4: exercise 3 - implement map in terms of fold
author
Ramakrishnan Muthukrishnan
<ram@rkrishnan.org>
Sat, 20 Dec 2014 07:20:36 +0000
(12:50 +0530)
committer
Ramakrishnan Muthukrishnan
<ram@rkrishnan.org>
Sat, 20 Dec 2014 07:20:36 +0000
(12:50 +0530)
hw4/hw4.hs
patch
|
blob
|
history
diff --git
a/hw4/hw4.hs
b/hw4/hw4.hs
index 780ee46864fa9404b5d4cf32f1bdeae19e8a8f30..455d8b9e6f20b7b9a78ba296ac1d7361252f896a 100644
(file)
--- a/
hw4/hw4.hs
+++ b/
hw4/hw4.hs
@@
-68,4
+68,16
@@
foldTree :: [a] -> Tree a
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