我之前已经问过这个问题,但之前问题的答案都没有对我有用,所以我会尝试不同的方法。
我做到了这一点:
> 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)
答案 0 :(得分:1)
which
是数据类型的名称;它不是构造函数。相反,您必须按如下方式创建树:
> val mytree = Node(Leaf(INT 2), Leaf(STRING "6"));