ocaml - 在 utop 中很好地打印值

标签 ocaml 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手册的部分。

关于ocaml - 在 utop 中很好地打印值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45245309/

相关文章:

emacs - utop 错误 : No such package: sexplib. 语法 - `core.syntax' 需要

ocaml - 如何在utop中使用ppx导出?

module - 如何在 utop 中加载 .ml 文件及其对应的 .mli 文件?

ocaml - 如何在ocaml中舍入一个数字?

functional-programming - 已安装 ocamlfind (findlib),但在 Mac 中始终找不到任何额外的包

functional-programming - OCaml中的fold_tree

ocaml - 接收 Stdlib.Scanf.Scan_failure : character '\\n'

OCaml 的 utop : importing external modules

ocaml - 获取 OCaml 中 float 的精度

erlang - 为什么 OCaml 的模式匹配比 Erlang 的弱?