在类型上使用'with sexp'会产生“警告4:此模式匹配很脆弱”

时间:2015-12-27 17:00:45

标签: pattern-matching ocaml compiler-warnings s-expression

我刚开始在自定义类型上使用with sexp语法扩展(描述为herehere)。但是,我注意到,当我这样做时,我会收到有关我的类型的以下警告:

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和{{1} })。

我通常会尝试修改编译中的任何警告;有没有办法让编译器在这里开心(没有让它完全抑制所有情况下的警告)?

编辑:用于降价格式化。

更新:提供Sexp.Atom的示例代码。

hit.ml

生成此警告:

open Core.Std open Option.Monad_infix open Battey.Kernel type hit = (sentence * int) with sexp

其他信息:我在macbook(Yosemite)上使用版本4.02.3的ocamlc(通过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.安装)并使用版本113.00.00 opam和{{1} }。我也在使用core作为我的cflags。

对延迟更新表示歉意;假期使我远离我的笔记本电脑/互联网连接。

感谢您的反馈!

1 个答案:

答案 0 :(得分:0)

我认为这是由使用类似

之类的东西引起的
match t with
| A -> 0
| B -> 1
| _ -> 2

如果type t = A | B | C,这看起来很好。但是当稍后添加构造函数D时,_将匹配它,通常这不是你想要的。看起来你不能做任何事情,但忽略警告。