請問您可以告訴我如何解決這個錯誤在我的代碼?haskell中的高階函數Error2
{--------------------- BINARY TO DECIMAL MENU ---------------}
functionBinToDecimal:: IO()
functionBinToDecimal= do
putStrLn("\n\tConvert Binary To Decimal\n")
putStrLn("----------------------------------------------------------\n")
putStrLn("\t\tEnter a binary number : ")
input<-getLine
let n=(read (reverse input))::String
let result = convertionFrom binaryToDec n
putStrLn(show result)
{----------------BINARY TO DECIMAL---------------------}
binaryToDec :: String -> Int
binaryToDec = foldr (\x s -> s * 2 + x) 0 . reverse . map charToInt
where charToInt x = if x == '0' then 0 else 1
conversionFrom :: (String -> Int) -> String -> Int
conversionFrom _ [] = 0
conversionFrom f (x:xs) = f x ++ conversionFrom f xs
錯誤
test.hs:28:27:
Couldn't match expected type `Int' with actual type `[a0]'
In the expression: f x ++ conversionFrom f xs
In an equation for `conversionFrom':
conversionFrom f (x : xs) = f x ++ conversionFrom f xs
旁註:它拼寫爲「轉換」,而不是「轉換」。 – dflemstr 2012-02-08 06:39:58
您**瞭解**錯誤信息的含義? [我昨天解釋](http://stackoverflow.com/a/9177409/86622)如何閱讀這種錯誤信息。 – dave4420 2012-02-08 07:59:12