ocaml 函数应用了太多参数

ocaml function applied too many arguments

我尝试使用下面的代码从 i -> 0 进行递归并输出白色 space

let print_tab fmt i = 
    match i with
    | 0 -> put fmt "%s" "" 
    | _ -> put fmt "%s" "    " ; print_tab fmt (i-1)

但是它不起作用,显示如下错误

 Error: This function is applied to too many arguments;
 maybe you forgot a `;'

我试过另一个密码

let print_tab fmt = function
    | 0 -> put fmt "%s" "" 
    | j -> put fmt "%s" "    " ; print_tab fmt (j-1)

但是还是报同样的错误,怎么了?

错误是您忘记了 rec,因此您的函数不是递归的,并尝试使用先前定义的 print_tab.

版本