1
我從來沒有在#1見過這個具體問題和其他問題沒有幫助我(我以前試過開)。無法匹配預期的類型`[字符]「與實際類型'一」
當我嘗試打印二叉樹這種方式如下:
data BinTree a = ET | Branch (BinTree a) a (BinTree a) deriving Show
ejC:: BinTree a -> String
ejC ET = ""
ejC (Branch x y z) = (ejC x) ++ "|-" ++ y ++ "-|" ++ (ejC z)
模塊給出了這樣的錯誤:
Couldn't match expected type `[Char]' with actual type `a'
`a' is a rigid type variable bound by
the type signature for ejC :: BinTree a -> String at Types2.hs:24:7
Relevant bindings include
z :: BinTree a (bound at Types2.hs:26:17)
y :: a (bound at Types2.hs:26:15)
x :: BinTree a (bound at Types2.hs:26:13)
ejC :: BinTree a -> String (bound at Types2.hs:25:1)
In the first argument of `(++)', namely `y'
In the second argument of `(++)', namely `y ++ "-|" ++ (ejC z)'
謝謝大家。
'(EJC X)++ 「| - 」 ++Ÿ++ 「 - |」 ++(ejC z)'應該是'(ejC x)++「| - 」++ show y ++「 - |」 ++(ejC z)' – Alec
您的解決方案工作。所以如此如此如此感謝。 –