Add exercises.hs

This commit is contained in:
akp 2023-10-25 17:13:08 +01:00
parent 807dce7ea7
commit 1948b515a1
No known key found for this signature in database
GPG key ID: CF8D58F3DEB20755

13
week4/exercises.hs Normal file
View 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)