“Printf.fprintf”的捷径

时间:2013-09-09 22:05:45

标签: printing ocaml

由于我在程序中使用了很多Printf.fprintf stdout ...,我想用更短的函数重命名它。所以我写道:

let p = Printf.fprintf stdout

我希望p "%s" "string"有效。但是,编译会出错:

File "lib/utility.ml", line 27, characters 8-29:
Error: The type of this expression, ('_a, out_channel, unit) format -> '_a,
       contains type variables that cannot be generalized

有没有人有想法重命名它以便应用程序尽可能简单?

1 个答案:

答案 0 :(得分:1)

我认为如果你扩展你的定义它会起作用:

let p fmt = Printf.fprintf stdout fmt
相关问题