我刚刚开始在我的定制类型上使用with sexp语法扩展(描述了这里和这里)。然而,我注意到,当我这样做时,我会收到以下关于我的类型的警告:
Warning 4: this pattern-matching is fragile. It will remain exhaustive when constructors are added to type Sexplib.Type.t.
我假设这是因为由with sexp语法生成的sexp转换器只处理为Sexp (Sexp.List和Sexp.Atom)定义的类型构造函数。
我通常尝试修复编译中的任何警告;是否有一种方法可以让编译器在这里高兴(除了让它完全抑制所有情况下的警告)?
编辑:用于减价格式。
更新:提供来自hit.ml的示例代码。
open Core.Std
open Option.Monad_infix
open Battey.Kernel
type hit = (sentence * int) with sexp生成此警告:
File "hit.ml", line 6, characters 5-27: Warning 4: this pattern-matching is fragile. It will remain exhaustive when constructors are added to type Sexplib.Type.t.
其他信息:我正在使用macbook (Yosemite)上安装的ocamlc 4.02.3版本(通过opam安装),并使用core和core_kernel的113.00.00版本。我还使用-w A作为我的标记。
很抱歉没有及时更新;假期让我远离了我的笔记本电脑/互联网连接。
谢谢你的反馈!
发布于 2017-03-30 11:34:56
我相信这是由于使用了
match t with
| A -> 0
| B -> 1
| _ -> 2如果type t = A | B | C的话,这看起来很好。但是,当稍后添加构造函数D时,_将只匹配它,通常这不是您想要的。看起来你没有什么可以做的,只是忽略了这个警告。
https://stackoverflow.com/questions/34482697
复制相似问题