-- good version quick sort quickSort::[Int]->[Int] quickSort [] = [] quickSort [x] = [x] quickSort l = quickSort(left) ++ [p] ++ quickSort right where left = [x | x <- init l, x < p] right = [x | x <- init l, x >= p] p = last l -- shorter version quick sort quickSort'::[Int]->[Int] quickSort' [] = [] quickSort' (x:xs) = quickSort' ([ l | l <- xs, l < x]) ++ [x] ++ quickSort' ([ r | r <- xs, r >= x]) -- more general version. -- e.g. quickSort1 ["b", "a"] -- output ["a", "b"] -- note: quickSort1 [] -- get error -- print quickSort1 ([]::Int) -- it works quickSort1::(Ord a)=>[a]->[a] quickSort1 [] = [] quickSort1 (x:xs) = quickSort1([ l | l <- xs, l < x ]) ++ [x] ++ quickSort1 ([ r | r <- xs, r >= x])