所以我试图创建一个错误的排序函数,给定一个列表,在删除重复项时对其进行排序,然后用“0”填充列表的开头,以确保排序严重的新列表的长度为与原始列表的大小相同。
这是我的代码:
dodgySort4 xs = (replicate ((length xs) - (length (badQuick xs)) 0) : badQuick xs
where
badQuick [] = []
badQuick (x:xs) = (badQuick lesser) ++ [x] ++ (badQuick greater)
where
lesser = filter (< x) xs
greater = filter (> x) xs
但是,我一直在第一个开始的时候得到“输入'解析错误,哪里'”错误,我不太确定问题是什么?
答案 0 :(得分:2)
这不是where
,)
中replicate
不匹配。该类型也不匹配,将:
更改为++
以解决问题。
dodgySort4 :: (Ord a, Num a) => [a] -> [a]
dodgySort4 xs = (replicate ((length xs) - (length (badQuick xs))) 0) ++ badQuick xs
where ...