我是Haskell的新手。在下面的示例中,该函数从列表中删除所有特定元素,并返回一个新列表。另外,我正在尝试使用辅助函数来获取返回的列表并输出它的长度。
我遇到的问题是编译期间的解析错误,指向包含delete _ [] = []
的行。
我很感激找到错误原因的任何帮助。
countDelete y (x:xs) = length outputList
where outputList = delete y (x:xs)
delete _ [] = []
delete y (x:xs) | x==y = delete y xs
| otherwise = x:delete y xs
答案 0 :(得分:4)
where
子句中的所有绑定必须从同一列开始,
countDelete y (x:xs) = length outputList
where
outputList = delete y (x:xs)
delete _ [] = []
delete y (x:xs)
| x==y = delete y xs
| otherwise = x:delete y xs
作品。