Ich folgte dem Buch, um den Baumdatentyp zu definieren, aber show funktioniert nicht richtig. Warum?Warum kann Haskell nicht den Baumtyp ableiten?
data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show)
test = show EmptyTree
gibt die Fehlermeldung:
No instance for (Show a0) arising from a use of ???show???
The type variable ???a0??? is ambiguous
Note: there are several potential instances:
instance Show a => Show (Tree a)
-- Defined at /Users/gzhao/Documents/workspace/hsTest2/src/Tree.hs:3:62
instance Show Double -- Defined in ???GHC.Float???
instance Show Float -- Defined in ???GHC.Float???
...plus 25 others
In the expression: show EmptyTree
In an equation for ???test???: test = show EmptyTree
Wie werden Sie diesen Code ausgeführt wird? Verwenden Sie einen Interpreter (ghci)? Diese Zeile: 'test = show EmptyTree' ist keine gültige Haskell-Syntax, also fügen Sie wahrscheinlich nicht Ihren gesamten Code ein. – rburny
@rburny Ich denke, das OP hat das in der Quelldatei. – Sibi
Ich benutze Eclipse –