我在一个ocaml函数调用期间遇到了编译错误

时间:2015-08-12 17:36:33

标签: ocaml

感谢您的关注。我遇到了一个ocaml funcion调用问题。在这里。

这是功能定义。假设这些是在pp.ml中定义的。

    let ast_exp_to_string = pp2string (fun p -> p#ast_exp ~prec:0)

    let ast_exp_to_string_in_varctx ctx = pp2string_with_pp ctx 
    (fun p-> p#ast_exp ~prec:0)


    let pp2string f v =
      let strpp = new pp ft in
      pp2string_with_pp strpp f v

    let pp2string_with_pp pp f v =
      Format.pp_open_box ft 0;
      f pp v;
      Format.pp_print_flush ft ();
      let s = Buffer.contents buf in
      Buffer.reset buf;
      s

    let make_varctx () =
      new pp ft

我可以成功调用 ast_exp_to_string ,就像这样 Pp.ast_exp_to_string e

但是当我用

打电话给 ast_exp_to_string_in_varctx
    let varctx = Pp.make_varctx;;

    Pp.ast_exp_to_string_in_varctx varctx e

我收到了如下编译错误:

Error: This expression has type unit -> Pp.pp
       but an expression was expected of type
         < ast_exp : prec:int -> 'a -> 'b; .. >
你可以帮我看一下吗?可能有什么不对?提前谢谢!

1 个答案:

答案 0 :(得分:0)

您忘记将参数应用于函数varctxt。它接受一个unit类型的参数。所以正确的代码是:

let varctx = Pp.make_varctx ();;
Pp.ast_exp_to_string_in_varctx varctx e