开发者

Print to standard output in SML

开发者 https://www.devze.com 2023-02-17 11:55 出处:网络
datatype term = node of string*term list 开发者_运维百科| vnode of string I have a value of type term. How do I print it in SML to the standard output?You need to first create a string out of the te
datatype term = node of string*term list
       开发者_运维百科  | vnode of string

I have a value of type term. How do I print it in SML to the standard output?


You need to first create a string out of the term and then print that using print. To turn a term into a string, you could define a function like this:

fun termToString (node (str, terms)) =
    "node(" ^ str ^ ", " ^ termListToString terms ^ ")"
  | termToString (vnode str) =
    "vnode(" ^ str ^ ")"
and termListToString terms =
    "[" ^ String.concatWith ", " (map termToString terms) ^ "]"
0

精彩评论

暂无评论...
验证码 换一张
取 消