ocaml - Re.re 和 sexp.opaque :无法编译
问题描述
我无法成功编译以下代码
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
由于声明,这不应该发生(这将避免从见janestreet ppx_sexp_conv[@sexp.opaque]
返回一个 sexp 表单)Re.re
我正在使用ocaml-4.07.1
.
解决方案
看起来这个功能还没有向公众发布,可能它会作为发布的一部分v0.13
发布。
如果我们查看最新(2019 年 4 月)ppx_sexp_conv 包的 README 文件,我们将找不到任何提及[@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_opaque
把戏。所以在当前时间点留给我们的就是使用它,例如,
type t =
| Default
| Regexp of
{ re : Re.re sexp_opaque;
; a : int
}
'a sexp_opaque
类型构造函数被定义为'a sexp_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]
推荐阅读
- oracle-apex - Oracle Apex 19.1 类图表 100% 区域宽度
- mysql - 无法使用 AWSAuthenticationPlugin 和 terraform 创建 mysql 用户
- angular - 如何将 webapi windows 身份验证与 Angular 应用程序一起使用
- reactjs - Nginx在动态根目录上找不到文件
- java - JavaFX 缺少 Legend 类
- excel - 如何根据范围将多个单元格值作为注释分配给单元格
- c# - 有没有办法在不为每个文件设置“复制到输出目录”属性的情况下“复制如果较新”文件夹中的所有文件?
- sql - SQL - 显示组和子组
- c# - 是给定类型的泛型类型参数
- jmeter - 标记 Jmeter 测试用例