gpt4 book ai didi

haskell - 此 "No Instance"错误的解决方法是什么?

转载 作者:行者123 更新时间:2023-12-02 20:53:54 25 4
gpt4 key购买 nike

我创建了描述二叉树的新类型

data BinTree a = Null | Num a (BinTree a) (BinTree a)
deriving (Show)

并创建了以下函数:

treehandle :: BinTree a -> Bool
treehandle a = True

至少检查输入值。

当我输入值Null时,程序成功输出结果,但无法输入二叉树。我这样尝试:

treehandle (5 (Null) (Null))

但获得:

<interactive>:66:13:
No instance for (Num (BinTree a1 -> BinTree a2 -> BinTree a0))
(maybe you haven't applied enough arguments to a function?)
arising from the literal ‘5’
In the expression: 5
In the first argument of ‘treehandle’, namely ‘(5 (Null) (Null))’
In the expression: treehandle (5 (Null) (Null))

为什么?

最佳答案

您忘记了值构造函数的名称

treehandle (Num 5 (Null) (Null))

关于haskell - 此 "No Instance"错误的解决方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54295744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com