Haskell 的 ghci
可以很好地打印属于实现 Show
类型类的类型的任何值。 OCaml 中是否有任何等效项可以让 utop 很好地自动打印用户定义类型的值?每行输入 x |> M.to_string
非常乏味......
最佳答案
在您的类型 M.t
的模块中定义函数:
val pp : Format.formatter -> t -> unit
然后,您可以使用以下命令安装适用于 ocaml
或 utop
中类型的打印机:
# #install_printer M.pp
请参阅toplevel directive手册的部分。
关于ocaml - 在 utop 中很好地打印值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45245309/