datatype term = node of string*term list
| vnode of string
我的类型为 term 。如何在SML中将其打印到标准输出?
答案 0 :(得分:3)
您需要先从term
创建一个字符串,然后使用print
进行打印。要将term
转换为字符串,您可以定义如下函数:
fun termToString (node (str, terms)) =
"node(" ^ str ^ ", " ^ termListToString terms ^ ")"
| termToString (vnode str) =
"vnode(" ^ str ^ ")"
and termListToString terms =
"[" ^ String.concatWith ", " (map termToString terms) ^ "]"