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
您的解决方案工作。所以如此如此如此感谢。 –