-3
我有以下循環:OCaml的表達式類型unmatchings
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
和我有以下println函數「我必須以這種方式使用」;
let println x =
printf "%s\n" (show x)
爲了打印以下:
println (`App(`App(`App(`Bstar, `K), `K), `K));;
當我運行它,我得到"printf "%s\n" (show x)"
線以下錯誤:
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
哪裏是我的錯?我該如何解決它?
我想打印以下值:
"B* K K K」
沒有足夠的上下文來推理您的錯誤。嘗試讓自己的問題獨立,但足夠小,以便體力勞動可以閱讀。 – camlspotter
我還會寫什麼?我寫了整個代碼。 – yusuf
好的smartass,只是downvote我。因爲看起來你沒有更好的事情去做,只是你不明白某些事情,而且你不喜歡它。這是你的角色。 – yusuf