Eric Fossum
Eric Fossum

Reputation: 2461

Standard ML binary tree datatype

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

Answers (1)

pad
pad

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

Related Questions