Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops ocaml表达式类型不匹配_Loops_Ocaml_Println - Fatal编程技术网

Loops ocaml表达式类型不匹配

Loops ocaml表达式类型不匹配,loops,ocaml,println,Loops,Ocaml,Println,我有以下循环: 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 |

我有以下循环:

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函数“我必须以这种方式使用”

要打印以下内容:

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”

不要将
show
传递给
println

println (`App(`App(`App(`Bstar, `K), `K), `K))
另外,对于K案例,
“I”^acc
可能应该是
“K”^acc

确保您正在使用
以在顶层分离术语。如果你有

let println x =
  Printf.printf "%s\n" (show x)

println (`App(`App(`App(`Bstar, `K), `K), `K))
println
(`App…
将被视为
printf
的参数。像这样把它们分开:

let println x =
  Printf.printf "%s\n" (show x)
;;

println (`App(`App(`App(`Bstar, `K), `K), `K))

我还是会出错。我正在编辑问题,将把错误放在那里。没有足够的上下文来解释你的错误。试着让你的问题独立但足够小,这样ppl就可以阅读了。我还要写什么?整个代码都是我写的。好吧,聪明人,投我一票。因为你似乎没有更好的事情要做,只是你不明白一些事情,你投了反对票。这是你的角色。
let println x =
  Printf.printf "%s\n" (show x)
;;

println (`App(`App(`App(`Bstar, `K), `K), `K))