Podążyłem za książką, aby zdefiniować typ danych Drzewa, ale show nie działa poprawnie. Czemu?Dlaczego Haskell nie może wnioskować o typie drzewa?
data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show)
test = show EmptyTree
daje komunikat o błędzie:
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
Jak masz uruchomiony ten kod? Czy używasz tłumacza (ghci)? Ta linia: 'test = show EmptyTree' jest nieprawidłową składnią Haskell, więc prawdopodobnie nie wklejasz całego kodu. – rburny
@rburny Myślę, że OP ma to w pliku źródłowym. – Sibi
Używam Eclipse –