我想打印一个类型的方法的结果int * int.
我试过这样的:
printf "%d %d\n" (find (99, 10));;
Run Code Online (Sandbox Code Playgroud)
但是,我得到了:
Error: This expression has type int * int
but an expression was expected of type int
Run Code Online (Sandbox Code Playgroud)
我在这里看了http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html但是没有提到元组.
那么打印元组的正确方法是什么?
你可以贬低它,例如,
let (x,y) = find (99,10) in
printf "%d %d\n" x y
Run Code Online (Sandbox Code Playgroud)
或者,您可以定义元组打印机,例如,
let pp_int_pair ppf (x,y) =
fprintf ppf "(%d,%d)" x y
Run Code Online (Sandbox Code Playgroud)
然后将它与说明%a符一起使用,例如
printf "%a\n" pp_int_pair (find (99,10))
Run Code Online (Sandbox Code Playgroud)