caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pierrick Couderc <pierrickcouderc@gmail.com>
To: Andre Nathan <andre@digirati.com.br>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Segfault with open GADTs
Date: Tue, 18 Oct 2016 15:10:42 +0200	[thread overview]
Message-ID: <CA+gYG2tR3t_=Q9Gzm8SRtdPbpJy9YTtcZENEGE6Nqd87mFNcWw@mail.gmail.com> (raw)
In-Reply-To: <f2b5b4ca-c348-25c1-3b47-b4e39e86ada0@digirati.com.br>

[-- Attachment #1: Type: text/plain, Size: 1358 bytes --]

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
>
>

[-- Attachment #2: Type: text/html, Size: 1974 bytes --]

  reply	other threads:[~2016-10-18 13:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-18 12:47 Andre Nathan
2016-10-18 13:10 ` Pierrick Couderc [this message]
2016-10-18 13:52   ` Andre Nathan
2016-10-18 14:21     ` Goswin von Brederlow
2016-10-18 14:50       ` Andre Nathan
2016-10-18 13:16 ` Jeremy Yallop

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+gYG2tR3t_=Q9Gzm8SRtdPbpJy9YTtcZENEGE6Nqd87mFNcWw@mail.gmail.com' \
    --to=pierrickcouderc@gmail.com \
    --cc=andre@digirati.com.br \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).