Ocaml Re.Re和sexp.不透明:无法编译
我无法成功编译以下代码Ocaml Re.Re和sexp.不透明:无法编译,ocaml,Ocaml,我无法成功编译以下代码 open Base open Sexplib.Std module Myregexp = struct type t = | Default | Regexp of { re : (Re.re [@sexp.opaque]) ; a : int } [@@deriving sexp] let default = Default end 关联的dune文件: (library (name myre
open Base
open Sexplib.Std
module Myregexp = struct
type t =
| Default
| Regexp of
{ re : (Re.re [@sexp.opaque])
; a : int
}
[@@deriving sexp]
let default = Default
end
关联的dune
文件:
(library (name myregexp)
(libraries base re sexplib) (preprocess (pps ppx_jane ppx_sexp_conv)))
构建命令是:dune build myregexp.a
我得到一个错误:
File "myregexp.ml", line 9, characters 16-21:
Error: Unbound value Re.re_of_sexp
由于[@sexp.不透明]
语句(这将避免从Re.Re
返回sexp表单,请参阅),因此不会出现这种情况
我使用的是
ocaml-4.07.1
这项功能似乎尚未向公众发布,可能会作为v0.13
版本的一部分发布
如果我们查看最新(2019年4月)ppx_sexp_conv软件包的自述文件,我们将不会发现任何关于[@sexp.opaque]
$ opam source ppx_sexp_conv.v0.12.0
$ grep sexp.opaque ppx_sexp_conv.v0.12.0/README.org
converters, simply apply the qualifier =sexp_opaque= as if it were a
type foo = int * stuff sexp_opaque [@@deriving sexp]
正如我们所看到的,只有旧的sexp\u不透明技巧。因此,在当前时间点留给我们的是使用它,例如
type t =
| Default
| Regexp of
{ re : Re.re sexp_opaque;
; a : int
}
'a sexp\u opaque
类型构造函数定义为'a sexp\u opaque='a
,除非sexp转换器将其视为不透明元素
最有可能的是,这将与JS库的未来版本决裂,因此我建议您使用一种更加冗长但稳定的解决方案:
type regex = Re.t
let sexp_of_regex = sexp_of_opaque
let regex_of_sexp = opaque_of_sexp
type t =
| Default
| Regexp of
{ re : regex;
; a : int
}
[@@deriving sexp]
您使用的是哪个版本的ppx_sexp_conv?我相信他们只在v0.12中添加了它。(变更日志帮助不大)我刚刚迁移到v0.12(我以前使用过v0.11.2),但没有任何进展。我也尝试过用sexp_不透明代替sexp.不透明,但仍然失败。