I've searched and found several people asking this question, but I can't find an explicit answer. How can I print a non-string in sml?
For example if I have an instance of an ADT, i.e., of a type declared by datatype, and I would like to print the value for debugging. Am I responsible for writing a function which converts such an object to a string, and then print the string? Or is there some printer library I should use? Or is there some sort of printObject or toString function?
Also how can I print other non-string objects such as true and false?
It would appear that sml knows how to print such objects, because when I compile a file using C-l in emacs, I see output such as the following, showing that sml does know how to print the values.
[opening /Users/jimka/Repos/mciml/ex1.1.sml]
type key = string
datatype tree = LEAF | TREE of tree * string * tree
val empty = LEAF : tree
val insert = fn : key * tree -> tree
val member = fn : key * tree -> bool
val t1 = TREE (LEAF,"a",LEAF) : tree
val t2 = TREE (LEAF,"a",TREE (LEAF,"c",LEAF)) : tree
val t3 = TREE (LEAF,"a",TREE (TREE (LEAF,"b",LEAF),"c",LEAF)) : tree
val it = true : bool
val it = () : unit