【问题标题】:@@deriving sexp is not working on utop@@deriving sexp 不适用于 utop
【发布时间】:2018-12-18 17:11:06
【问题描述】:

我在 utop 中运行这段代码:

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

但是没有生成 s-expression 转换器的预期声明。

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

Ocaml 的版本是 4.06.1。

谢谢。

【问题讨论】:

    标签: ocaml utop


    【解决方案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>
    

    【讨论】:

    • 谢谢您,您的回答有效,唯一的问题是它需要安装包 ppx_deriving,如下所述:github.com/janestreet/ppx_sexp_conv/issues/21
    • 另外,它只适用于utop -require ppx_sexp_conv,而不是open Sexplib.Std,我可以open Coreopen Base
    • 啊,对。感谢您提供额外的信息。确实有几种方法可以使用这个派生器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2014-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多