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)
4

1 回答 1

1

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

> val mytree = Node(Leaf(INT 2), Leaf(STRING "6"));
于 2011-11-02T20:16:26.607 回答