Tôi đã theo dõi sách để xác định loại dữ liệu Cây, nhưng chương trình không hoạt động chính xác. Tại sao?Tại sao Haskell không thể suy ra Kiểu cây?
data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show)
test = show EmptyTree
cung cấp cho các thông báo lỗi:
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
Làm thế nào bạn có đang chạy mã này? Bạn đang sử dụng thông dịch viên (ghci)? Dòng này: 'test = show EmptyTree' không phải là cú pháp Haskell hợp lệ, vì vậy bạn có thể không dán tất cả mã của mình. – rburny
@ rburny Tôi nghĩ rằng OP có trong tệp nguồn. – Sibi
Tôi đang sử dụng Eclipse –