I am writing an SML binary search tree code and I am debugging the inorder, preorder, and postorder. I keep getting an error that says:
stdIn:11.1-11.30 Error: operator and operand do not agree [tycon mismatch]
operator domain: ?.tree * string
operand: tree * string
in expression:
preOrderWrite (t4,"tree.txt")
I know what tycon mismatch is, but I don't know why tree has a ?. in front of it. This is the tree:
val t4 = node(8, node(5, node(2, leaf, leaf), node(6, leaf, leaf)), node(11, leaf, node(12, leaf, leaf)));
And this is the code for the orders:
fun preOHelp(leaf) = []
| preOHelp(node(data, left, right)) = [data] @ preOHelp(left) @ preOHelp(right);
fun preOrderWrite(tree,fileName) = let
val outfile = TextIO.openOut(fileName)
val theList = toText(preOHelp(tree))
in
TextIO.output(outfile, theList);
TextIO.closeOut(outfile)
end;
inOrderWrite : tree * string -> unit*)
fun inOHelp(leaf) = []
|inOHelp(node( data, left, right)) = inOHelp(left) @ [data] @ inOHelp(right);
fun inOrderWrite(tree,fileName) = let
val outfile = TextIO.openOut(fileName)
val theList = toText(inOHelp(tree))
in
TextIO.output(outfile, theList);
TextIO.closeOut(outfile)
end;
postOrderWrite : tree * string -> unit*)
fun postOHelp(leaf) = []
| postOHelp(node( data, left, right)) = postOHelp(left) @ postOHelp(right) @ [data];
fun postOrderWrite(tree,fileName) = let
val outfile = TextIO.openOut(fileName)
val theList = toText(postOHelp(tree))
in
TextIO.output(outfile, theList);
TextIO.closeOut(outfile)
end;
And this is the to text code:
fun toText [] = ""
| toText[x,xs] = Int.toString(x)^" "^toText(xs);