有谁知道为什么这仍然给我错误?
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
check
期望将元组作为第一个论点;因此,对其进行的所有调用(无论在其内部main
还是在其内部)都check
必须将其传递给一个元组。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句