Taking the functional programming plunge and trying to teach myself Haskell from online materials. Probably pretty basic, but I cannot figure why my implementation of quicksort does not terminate for any input list with length longer than 1.
Here's the code:
quicksort :: (Ord ord) => [ord] -> [ord
quicksort [] = []
quicksort [element] = [element]
quicksort array = quicksort right_half ++ [pivot] ++ quicksort left_half
where pivot = head array
right_half = [element | element <- array, element <= pivot]
left_half = [element | element <- array, element > pivot]
I was reading an online textbook but decided to try the quicksort for myself before just reading the given solution. After failing, I went back and understood the given answer, but still cannot see why mine is wrong. Any help for this haskell newbie would be appreciated!