1
有沒有人知道爲什麼這仍然給我錯誤?Haskell在交換列表元素中的錯誤
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
此錯誤消息說,有關的I型甚至不明白:
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」的簽名嗎? – bheklilr
看起來像您打電話時檢查'main'中的錯誤參數。它的第一個參數是一個元組,並且只傳遞一個列表。另外,它看起來像檢查是純粹的,所以也許你的意思是'main = print $ check(something,[4,3,2])0 1'? –
這是真的感謝,但仍然是同樣的問題 – Amir