5

I've just started using the with sexp syntax extension (described here and here) on my custom types. However, I've noticed that when I do, I get the following warning about my type:

Warning 4: this pattern-matching is fragile. It will remain exhaustive when constructors are added to type Sexplib.Type.t.

I'm assuming this is because the sexp converters that are generated by the with sexp syntax only handle the type constructors defined for Sexp (Sexp.List and Sexp.Atom).

I generally try to fix any warnings in my compilation; is there a way to make the compiler happy here (short of having it suppress the warning entirely for all cases)?

EDIT: for markdown formatting.

Update: Providing example code from hit.ml.

open Core.Std
open Option.Monad_infix

open Battey.Kernel

type hit = (sentence * int) with sexp

Generates this warning:

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.

Other info: I'm using version 4.02.3 of ocamlc (as installed via opam) on a macbook (Yosemite) and am using version 113.00.00 of core and core_kernel. I'm also using -w A for my cflags.

Apologies for the delay in updating; the holidays kept me away from my laptop/internet connection.

Thanks for the feedback!

user812376
  • 63
  • 4

1 Answers1

0

I believe this is caused by using something like

match t with
| A -> 0
| B -> 1
| _ -> 2

This looks fine if type t = A | B | C. But when later a constructor D is added the _ will just match it and usually that is not what you want. Doesn't look like there is anything you can do but ignore the warning though.

Goswin von Brederlow
  • 11,875
  • 2
  • 24
  • 42