Reputation: 2461
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)
Upvotes: 0
Views: 1153
Reputation: 41290
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"));
Upvotes: 1