Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print to standard output in SML

Tags:

sml

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?

like image 548
abhi Avatar asked Dec 02 '25 18:12

abhi


1 Answers

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) ^ "]"
like image 53
sepp2k Avatar answered Dec 05 '25 07:12

sepp2k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!