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 に答える