标准 ML 二叉树数据类型
我知道这个问题以前曾被问过,但之前问题中的答案都不适合我,所以我会尝试不同的方法。
我已经这样做了:
> datatype which = STRING of string | INT of int;
datatype which = INT of int | STRING of string
> datatype whichTree = Empty | Leaf of which | Node of whichTree*whichTree;
datatype whichTree = Empty | Leaf of which | Node of whichTree * whichTree
但是当我尝试构建一棵树时,
> val mytree = Node(Leaf(which 2), Leaf(which 6));
我遇到了错误。
Error-Value or constructor (which) has not been declared Found near
Node( Leaf(which(2)), Leaf(which(6)))
Error-Value or constructor (which) has not been declared Found near
Node( Leaf(which(2)), Leaf(which(6)))
Static errors (pass2)
I know this question has been asked before, but none of the answers in previous questions worked for me so I'll try a different approach.
I've done this:
> datatype which = STRING of string | INT of int;
datatype which = INT of int | STRING of string
> datatype whichTree = Empty | Leaf of which | Node of whichTree*whichTree;
datatype whichTree = Empty | Leaf of which | Node of whichTree * whichTree
but when I try to build a tree
> val mytree = Node(Leaf(which 2), Leaf(which 6));
I get errors.
Error-Value or constructor (which) has not been declared Found near
Node( Leaf(which(2)), Leaf(which(6)))
Error-Value or constructor (which) has not been declared Found near
Node( Leaf(which(2)), Leaf(which(6)))
Static errors (pass2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
which
是数据类型的名称;它不是一个构造函数。相反,您必须按如下方式创建一棵树:which
is the name of the datatype; it's not a constructor. Instead, you have to create a tree as follows: