我做的:類型的錯誤
Prelude> "sone" ++ "otehr"
"soneotehr"
但這樣的代碼:
addOneToElement :: [a] -> [a]
addOneToElement element = element ++ "next"
main = do
let s = addOneToElement("some")
putStrLn s
產生這樣的輸出:
all_possible_combinations.hs:22:37:
Couldn't match expected type `a' against inferred type `Char'
`a' is a rigid type variable bound by
the type signature for `addOneToElement'
at all_possible_combinations.hs:21:20
Expected type: [a]
Inferred type: [Char]
In the second argument of `(++)', namely `"next"'
In the expression: element ++ "next"
爲什麼我得到這個錯誤,我怎麼能解決它?
此外,你可以(也應該,這是毫無意義和困惑)放棄功能調用的parens。 – delnan 2010-10-18 11:40:26