編寫Haskell函數時出現問題。編譯器說:在應用Haskell - 應用程序中的類型錯誤
類型錯誤
表達:移動(偏移 - 1)(saveList子列表(X:XS))XS
test :: Int -> [Int] -> [Int]
test _ [] = []
test offset (xs) = move offset [] xs
where
move offset subList (x:xs) | offset == 0 = subList ++ rotate (last (x:xs)) (x:xs)
| otherwise = move (offset-1) (saveList subList (x:xs)) xs
saveList save (x:xs) = save ++ [x]
rotate _ [] = []
rotate item (x:xs) = item : (move x xs)
last (x:[]) = x
last (x:xs) = last xs
但我不能看到任何錯誤。我做錯了什麼?
好的坦克你。我是否也可以將類型簽名添加到where子句中的函數中? – Cilenco
@Cilenco是的,你可以,只需在功能相同的縮進級別添加類型簽名。 – svk