# 编译以下快速排序示例时，如何解决输入“ =”上的“解析错误”？

``````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
``````

`let`子句中两个声明的缩进应该匹配，如：

``````quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]  -- no extra spacing
in smallerSorted ++ [x] ++ biggerSorted``````

``````quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted  = quicksort [a | a <- xs, a > x]  -- extra space before =
in smallerSorted ++ [x] ++ biggerSorted``````

``````import Data.List(partition)

quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let (smal, big) = partition (x >) xs
in quicksort smal ++ x : quicksort big
``````

`partition`函数通常以这样的方式实现：它只在给定列表上迭代一次，并且只执行一次测试。因此，这通常比使用两个分别过滤给定列表的列表理解更有效（一点）。