Add exercises.hs
This commit is contained in:
parent
807dce7ea7
commit
1948b515a1
1 changed files with 13 additions and 0 deletions
13
week4/exercises.hs
Normal file
13
week4/exercises.hs
Normal file
|
@ -0,0 +1,13 @@
|
|||
fun :: Num a => (a -> a) -> (a -> Bool) -> [a] -> [a]
|
||||
fun f p xs = map f (filter p xs)
|
||||
|
||||
map' :: (a -> b) -> [a] -> [b]
|
||||
map' f xs = foldr ((:).f) [] xs
|
||||
|
||||
filter' :: (a -> Bool) -> [a] -> [a]
|
||||
filter' p xs = foldr (\x xs -> if (p x) then x:xs else xs) [] xs
|
||||
|
||||
altMap :: (a -> b) -> (a -> b) -> [a] -> [b]
|
||||
altMap fa fb xs = map
|
||||
(\(x, val) -> if x then fa val else fb val)
|
||||
(zip [x `mod` 2 == 1 | x <- [0..((length xs) - 1)]] xs)
|
Reference in a new issue