有谁知道为什么这仍然给我错误?
main = do
print $ check [4,3,2] 0 1
-- output expected [3,4,2], means just once check and swap not more
check ( modXs, []) _ _ = modXs
check ( modXs, [x]) _ _ = x : modXs
check ( modXs, (x1:x2:xs)) counter limit
| x1 > x2 && counter < limit = x2:check (x1 : xs) (counter+1) limit
| otherwise = x1 : check (x2 : xs) counter limit
这里的错误信息说的是关于我甚至不理解它的类型:
Couldn't match expected type `([a1], [a1])' with actual type `[a1]'
In the first argument of `check', namely `(x1 : xs)'
In the second argument of `(:)', namely
`check (x1 : xs) (counter + 1) limit'
In the expression: x2 : check (x1 : xs) (counter + 1) limit
答案 0 :(得分:3)
check
期望将一个元组作为其第一个参数;因此,所有对它的调用 - 无论是main
还是check
本身 - 都必须将它传递给元组。