解析Haskell中输入'where'的错误

时间:2017-03-24 06:17:50

标签: haskell

所以我试图创建一个错误的排序函数,给定一个列表,在删除重复项时对其进行排序,然后用“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

但是,我一直在第一个开始的时候得到“输入'解析错误,哪里'”错误,我不太确定问题是什么?

1 个答案:

答案 0 :(得分:2)

这不是where)replicate不匹配。该类型也不匹配,将:更改为++以解决问题。

dodgySort4 :: (Ord a, Num a) => [a] -> [a]
dodgySort4 xs = (replicate ((length xs) - (length (badQuick xs))) 0) ++ badQuick xs
  where ...