标准 ML 二叉树数据类型

发布于 2024-12-13 12:02:49 字数 727 浏览 4 评论 0原文

我知道这个问题以前曾被问过,但之前问题中的答案都不适合我,所以我会尝试不同的方法。

我已经这样做了:

> 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘过的浮云 2024-12-20 12:02:49

which 是数据类型的名称;它不是一个构造函数。相反,您必须按如下方式创建一棵树:

> val mytree = Node(Leaf(INT 2), Leaf(STRING "6"));

which is the name of the datatype; it's not a constructor. Instead, you have to create a tree as follows:

> val mytree = Node(Leaf(INT 2), Leaf(STRING "6"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文