我已经编写了许多类型为out_channel -> 'a -> unit
的漂亮打印机,现在我想要一段代码通过使用漂亮的打印机从值中获取字符串。通过使用漂亮的打印机从值中获取字符串
举例来说,我已经实现了以下功能:
type t =
{ x: int;
y: int }
let co = { x = 4; y = 5 }
let print (chan: out_channel) (co: t) : unit =
Printf.fprintf chan "(%d, %d)" co.x co.y
我觉得功能Printf.sprintf
可以帮助我得到字符串(4, 5)
。我试过Printf.sprintf "%a" print co
,它在print
:This expression has type out_channel -> t -> unit but an expression was expected of type unit -> 'a -> string
处给了我一个错误。
有没有人知道如何提醒这条线,或没有人有一个解决方案,而不是sprintf
?
这不是我想要的。我想我的功能'print'使用... – SoftTimur
我不不认为这是可能的。如果有人会做你想做的 - 我真的很想看到结果。 – Kakadu