Hi,

It is supposed to work, but it seems thepattern-matching compiler does not detect that M0.to_string is non exhaustive, thus it does not add a Match_Failure in case the variant is unknown. With extensible variants, a pattern matching is only exhaustive if you provide a wildcard or a variable for variants added afterwards. 

You maybe should report it on the bug tracker! 

2016-10-18 14:47 GMT+02:00 Andre Nathan <andre@digirati.com.br>:
Hi

I'm trying to use extensible variants to allow users to extend a type
from my library, which is a GADT, but it's resulting in a segfault when
the program is executed. I've managed to reproduce the issue with this code:

  module M0 = struct
    type 'a t = ..
    type 'a t +=
      | I : int -> int t
      | S : string -> string t
      | P : 'a t * 'b t -> ('a * 'b) t

    let rec to_string : type a. a t -> string = function
      | I i -> "I:" ^ string_of_int i
      | S s -> "S:" ^ s
      | P (x, y) -> to_string x ^ to_string y
  end

  module M1 = struct
    include M0
    type 'a t += T : 'a t -> 'a t

    let to_string = function
      | T t -> to_string t
      | x -> to_string x
  end

  let () =
    print_endline @@ M1.to_string (M1.P (M1.T (M1.I 42), M1.S "foo"))


Is this sort of thing supposed to work?

Thanks,
Andre