在 utop 中很好地打印值

Print values nicely in utop

Haskell 的 ghci 可以很好地打印属于实现 Show 类型类的类型的任何值。 OCaml 中是否有任何等价物可以让 utop 自动很好地打印用户定义类型的值?每行输入 x |> M.to_string 非常乏味……

在您的模块中为您的类型 M.t 定义函数:

val pp : Format.formatter -> t -> unit

然后您可以使用 ocamlutop 中的类型安装打印机:

# #install_printer M.pp

请参阅手册的 toplevel directive 部分。