Solution
let odd x = x `mod` 2 == 1
let even x = x `mod` 2 == 0
filter odd [1..10]
filter even [1..10]
Solution
let myfilter x = x `mod` 4 == 0 && x `mod` 3 /= 0
filter myfilter [1..20]
Solution
Prelude> foldr (:) [] [1..]
[1,2,3,4,5,6,7,8,9,10,...
Prelude> foldl (>:) [] [1..]
Solution
sum = foldl' (+) 0
product = foldl' (*) 1
length = foldl' (\acc _ -> acc + 1) 0
map f = foldr (\x acc -> f x : acc) []
map f = foldr ((:) . f) []
Solution
[] ++ ys = ys
xs ++ [] = xs
(x:xs) ++ ys = x:xs ++ xy
reverse [] = []
reverse (x:xs) = reverse xs ++ [x]
take _ [] = []
take n (x:xs) | n <= 0 = []
| otherwise = x : take (n-1) xs
drop _ [] = []
drop n xxs@(_:xs) | n <= 0 = xxs
| otherwise = drop (n-1) xs