Hi, I acknowledged that we have a tutorial in this conversion but I have a new type and I keep getting an error message for this conversion of the new type.
let rec expr_to_str (e:expr) : string = match e with
| Add (left, right) ->
"Add" ^ " (" ^ serialize left ^ ", " ^ serialize right ^ ")"
| Mul (left, right) ->
"Mul" ^ " (" ^ serialize left ^ "," ^ serialize right ^ ")"
| Val v -> "Val" ^ " (" ^ v ^ ")"
| If (expr1,expr2,expr3) ->
"If" ^ " (" ^ serialize expr1 ^ ", " ^ serialize expr2 ^ ", " ^ serialize expr3 ^ ")"
I have an error message on the “Val v” conversion:
Val v -> "Val" ^ " (" ^ v ^ ")"
Error: This expression has type value but an expression was expected of type string
Do I need another pattern matching on v? Since type value has Int, Bool and Closure.
Thank you!
Also note that there is a %S formatter (uppercase S) that will display a string in OCaml syntax, that is with surrounding double quotes and escaped special characters (such as double quotes).