我有一段代码如下:
let pp_e (chan: out_channel) (e: e) =
...
(* ternary operator *)
let tern (b: bool) v0 v1 =
if b then v0 else v1
let pp_x (chan: out_channel) (b: bool) (x: x) =
let e0, e1 = ... in
Printf.fprintf chan (tern b "(%a, %a)" "%a%a") pp_e e0 pp_e e1
Error: This expression has type string but an expression was expected of type
('a -> 'b -> 'c -> 'd -> 'e, out_channel, unit) format =
('a -> 'b -> 'c -> 'd -> 'e, out_channel, unit, unit, unit, unit)
format6
pp_x
不编译,因为它不再考虑"(%a, %a)"
和"%a%a"
作为一种格式。我还是想用一个三元函数,而不是if...then...else...
让代码更简洁。有谁知道如何修改代码?