小编Gar*_*hao的帖子

为什么Haskell不能推断Tree类型?

我按照本书来定义树数据类型,但show无法正常工作.为什么?

data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show)

test = show EmptyTree
Run Code Online (Sandbox Code Playgroud)

给出错误消息:

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 …
Run Code Online (Sandbox Code Playgroud)

haskell

7
推荐指数
1
解决办法
157
查看次数

标签 统计

haskell ×1