@@deriving sexp 不适用于 utop

@@deriving sexp is not working on utop

我是 运行 utop 中的这段代码:

# type u = { a: int; b: float } [@@deriving sexp];;

但是没有生成预期的 s 表达式转换器声明。

我安装了 Core 0.11.0 和 utop 版本 2.1.0。

Ocaml 版本为 4.06.1.

谢谢。

您需要传递 -require 以便加载 ppx。此外(特定于此驱动程序),您需要使用 -require sexplib 和手动 open Sexplib.Std:

在范围内传递其运行时
% utop -require ppx_sexp_conv -require sexplib                  
utop # open Sexplib.Std;;
utop # type u = { a: int; b: float } [@@deriving sexp];;
type u = { a : int; b : float; }
val u_of_sexp : Sexplib0.Sexp.t -> u = <fun>
val sexp_of_u : u -> Sexplib0.Sexp.t = <fun>