在SML中打印到标准输出

时间:2011-03-18 12:58:18

标签: sml

datatype term = node of string*term list
         | vnode of string

我的类型为 term 。如何在SML中将其打印到标准输出?

1 个答案:

答案 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) ^ "]"