I have the following loop:
let show expr =
let rec loop acc = function
| `S -> "S"^acc
| `K -> "I"^acc
| `I -> "I"^acc
| `App(a,b) -> (loop acc a)^(loop acc b)
| `B -> "B"^acc
| `C -> "C"^acc
| `Sprim -> "S'"^acc
| `Bprim -> "B'"^acc
| `Bstar -> "B*"^acc
| `Cprim -> "C'"^acc
| `Var(a) -> a^acc
| `Con(a) -> a^acc
in
loop "" expr
And I have the following println function "I must use in this way";
let println x =
printf "%s\n" (show x)
In order to print the following:
println (`App(`App(`App(`Bstar, `K), `K), `K));;
When I run it, I get the following error on "printf "%s\n" (show x)"
line:
Error: This expression has type
('a -> 'b -> 'c, out_channel, unit, unit, unit, 'a -> 'b -> 'c)
CamlinternalFormatBasics.fmt
but an expression was expected of type
('a -> 'b -> 'c, out_channel, unit, unit, unit, unit)
CamlinternalFormatBasics.fmt
Type 'a -> 'b -> 'c is not compatible with type unit
Where is my mistake? How can I fix it?
I want to print the following value:
"B* K K K”