haskell 4 recursive

Taking Notes from http://learnyouahaskell.com

1
2
3
4
5
6
7
:: (Ord a) => [a] -> a
[] = error "max of empty list"
[x] = x
(x:xs)
| x > maxTail = x
| otherwise = maxTail
where maxTail = max xs
1
2
3
4
5
6
7
8
9
deplicate :: (Num i, Ord i) => i -> a -> [a]
deplicate n x
| n <= 0 = []
| otherwise = x:replicate (n - 1) x
zip' :: [a] -> [b] -> [(a,b)]
zip' _ [] = []
zip' [] _ = []
zip' (x:xs) (y:ys) = (x,y):zip' xs ys
1
2
3
4
5
6
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted