Homework #6 Questions

Printing Trees

A possible help: A CS431 student has found the print function useful in debugging his code. You can use

(print ((Int.toString x) ^ "\n"); x + 1)
Notice how you use ; to separate the print statement from the thing you return from the expression.

Q: When I construct my (admittedly unbalanced) tree, it prints like

val it = Node (Empty,1,Node (Empty,2,Node #)) : int tree
But I put 5 nodes into the tree. What happened?

A: SML prints out structures only to a certain depth to avoid filling up your screen with lots of output. But this can be changed by setting the printDepth variable using:

Compiler.Control.Print.printDepth := 10;
By default the value is 5; set it to something bigger.