有谁知道为什么这仍然给我错误?
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