Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ocaml Re.Re和sexp.不透明:无法编译_Ocaml - Fatal编程技术网

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.不透明,但仍然失败。