Haskell Exercises Solutions
Haskell Exercises Solutions
where
a = 10
xs = [1,2,3,4,5]
n = a `div` length xs
where
a = 10
xs = [1,2,3,4,5]
-- Last function
last' [] = Nothing
second::[a] -> a
pair x y = (x, y)
double x = x * 2
palindrome xs = reverse xs == xs
twice f x = f (f x)
-- 1
safeTailPattern [] = []
safeTailPattern (x : xs) = xs
safeTailGuard xs
| null xs = []
| otherwise = drop 1 xs
-- 2
(||) _ _ = True
-- 3
and' (x : xs)
| not x = False
concat' [] = []
concat' [[]] = []
replicate' 0 _ = []
replicate' n a = a : replicate' (n - 1) a
(!!*) [] _ = Nothing
(!!*) (_ : as) n
| n < 0 = Nothing
| otherwise = (!!*) as (n - 1)
elem' _ [] = False
elem' a [x] = a == x
merge' [] [] = []
merge' [] ys = ys
merge' xs [] = xs
| x <= y = x : merge' xs ys
| otherwise = y : merge' xs ys
-- Curried Functions