I’ trying to print a types value in SML and with no success.
Please take a look at the code below and let me know what do I need to do in order to fix this.
Thanks.
(* Language Definition *)
datatype = Id of string;
(* Expression Definition *)
datatype expr =
Var of ident
| Num of int
| Plus of expr * expr
| Paren of expr;
val p = Id "x";
val p = Var p;
print(p);
This is my error:
stdIn:175.1-175.9 Error: operator and operand don't agree [tycon mismatch]
operator domain: string
operand: expr
in expression:
print p
I tried a lot of combination and castings but with no success.
As the compiler is trying to say,
printcan only be used to print strings. If you want to be able to print your specific type, you need a printing function tailored to your datatype. Painful, I know.Try this: