From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id C904880043 for ; Tue, 18 Oct 2016 15:11:05 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=pierrickcouderc@gmail.com; spf=Pass smtp.mailfrom=pierrickcouderc@gmail.com; spf=None smtp.helo=postmaster@mail-yw0-f171.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of pierrickcouderc@gmail.com) identity=pra; client-ip=209.85.161.171; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="pierrickcouderc@gmail.com"; x-sender="pierrickcouderc@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of pierrickcouderc@gmail.com designates 209.85.161.171 as permitted sender) identity=mailfrom; client-ip=209.85.161.171; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="pierrickcouderc@gmail.com"; x-sender="pierrickcouderc@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-yw0-f171.google.com) identity=helo; client-ip=209.85.161.171; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="pierrickcouderc@gmail.com"; x-sender="postmaster@mail-yw0-f171.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3ADCObxRQPXcYmiZc33u7gyVqA3dpsv+yvbD5Q0YIu?= =?us-ascii?q?jvd0So/mwa64ZhWN2/xhgRfzUJnB7Loc0qyN4vqmBDBLv87J8ChbNscTB1ld0Y?= =?us-ascii?q?RetjdjKfDGIHWzFOTtYS0+EZYKf35e1Fb/D3JoHt3jbUbZuHy44G1aMBz+MQ1o?= =?us-ascii?q?Ora9QdaK3Iyfntq/8JzLYghOmCH1IfYrdE33/k3tsZw/h4d4J+4XwwfJq30AL+?= =?us-ascii?q?1QyXllDV6SkBfm79uxupVk9mJaoaRy2dRHVPDCfqkiV71TD3wNNH056dfg/U3b?= =?us-ascii?q?TAaV/HoXUW4RjxZFGQPt4xTzX5O3uSz/4LkukBKGNNH7GOhnEQ+p6L1mHVqx0H?= =?us-ascii?q?8K?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CZAQCEHgZYhquhVdFcHAEBBAEBCgEBF?= =?us-ascii?q?wEBBAEBCgEBgxEBAQEBAYFwB40tlwaIS4ttggiGIgKBdwc4FAEBAQEBAQEBAQE?= =?us-ascii?q?BEgEBAQgLCwkZL4IyBAEVAQSCEQEBAwESEQQZARsdAQMBCwYFBAc3AgIiAREBB?= =?us-ascii?q?QEcBhMIGogVAQMPCKgigTI+MotCgWuCXwWDbQoZJw1TgwIBAQEBAQUBAQEBARo?= =?us-ascii?q?DBhCGLYRVh0uCWwWaBpAEj3WMe4I+Ex6BER5RKYJ9IIFgPDSHFYFBAQEB?= X-IPAS-Result: =?us-ascii?q?A0CZAQCEHgZYhquhVdFcHAEBBAEBCgEBFwEBBAEBCgEBgxE?= =?us-ascii?q?BAQEBAYFwB40tlwaIS4ttggiGIgKBdwc4FAEBAQEBAQEBAQEBEgEBAQgLCwkZL?= =?us-ascii?q?4IyBAEVAQSCEQEBAwESEQQZARsdAQMBCwYFBAc3AgIiAREBBQEcBhMIGogVAQM?= =?us-ascii?q?PCKgigTI+MotCgWuCXwWDbQoZJw1TgwIBAQEBAQUBAQEBARoDBhCGLYRVh0uCW?= =?us-ascii?q?wWaBpAEj3WMe4I+Ex6BER5RKYJ9IIFgPDSHFYFBAQEB?= X-IronPort-AV: E=Sophos;i="5.31,362,1473112800"; d="scan'208,217";a="241270400" Received: from mail-yw0-f171.google.com ([209.85.161.171]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 18 Oct 2016 15:11:04 +0200 Received: by mail-yw0-f171.google.com with SMTP id t193so137205060ywc.2 for ; Tue, 18 Oct 2016 06:11:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=5cIIWlO/NZ3YGrPnXJm9v7CpE3wB30CwgPIkvBu3Ouw=; b=l0BMMu123GTx3ofHO9nicy91oqpBLIwh+vD6o4AvUS55cz5aNhUnXANCm2YYFYx8oq YShF9IqufUvLwEhU7zPK3X+T5QJx8sJVJhDcvEVvVqRNcZOh+ri8QaOQfeuZCE50qh+n sBFHsabMTdqNJ2EaiEDXw3Jk57qX8oC462zCpMwaZiCeJaY9l6mzQbDutHM9O8Zlgw9Y aGlChu5LP3u+3NNp6x3VRUvc0ZynV411fs4AaaZmel9JnMu+hVFUpsG5KQbQrHIJTYRn MD1dgEK4KK8Oto5duknpa5sJSguDvANs3EFEeTEvWk0zV7wGE8dS34Bzybs9tFj1wfWN kdow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=5cIIWlO/NZ3YGrPnXJm9v7CpE3wB30CwgPIkvBu3Ouw=; b=LGmzxqz3nvg/dOD5phVJQV/Hs7gi3jwy9m4U25mh/0DtzFNlj6b64QR5POkI2hGJJX 0Q8RSQY20DfFx0RYNzWo5j4x+nr9XcPb4+h5oPLfxYII2PNiOWEWAf1QwlCj3UxR1ERY YmR0XqyGeZYFmPReN1WJdYsguGJdCaHDhr7buLeJ9J9L3rfFYGLhFba7UrQgte22xZl3 uagO8IUdrf1V3pg1f01wU6Dz2bciCdNQkuT4NJPaZ3JDlfFOgWYc2JtgU2KkTnNmjMRA pk2sC9HcaAhLFIBu058n0CZkHaJuxbKGVzuMfhVH7zw/oBEcprDerMOKrbbMfjziP671 vAjA== X-Gm-Message-State: AA6/9Rk3orruxqkPtB4cmmcLoxTCsfSQYzB6R4JO7CMJhIZinfuDovmmv9qUuJJyTf8nv+bSunGCy45gZIi2Lg== X-Received: by 10.28.229.194 with SMTP id c185mr11161507wmh.116.1476796263531; Tue, 18 Oct 2016 06:11:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.147.4 with HTTP; Tue, 18 Oct 2016 06:10:42 -0700 (PDT) In-Reply-To: References: From: Pierrick Couderc Date: Tue, 18 Oct 2016 15:10:42 +0200 Message-ID: To: Andre Nathan Cc: Ocaml Mailing List Content-Type: multipart/alternative; boundary=001a1146a00cb18cc0053f236c82 Subject: Re: [Caml-list] Segfault with open GADTs --001a1146a00cb18cc0053f236c82 Content-Type: text/plain; charset=UTF-8 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 : > 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 > > --001a1146a00cb18cc0053f236c82 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

It is supposed to work, but it seem= s thepattern-matching compiler does not detect that M0.to_string is non exh= austive, thus it does not add a Match_Failure in case the variant is unknow= n. With extensible variants, a pattern matching is only exhaustive if you p= rovide a wildcard or a variable for variants added afterwards.=C2=A0
<= div>
You maybe should report it on the bug tracker!=C2=A0

2016-10-1= 8 14:47 GMT+02:00 Andre Nathan <andre@digirati.com.br>:<= 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:

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

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

=C2=A0 module M1 =3D struct
=C2=A0 =C2=A0 include M0
=C2=A0 =C2=A0 type 'a t +=3D T : 'a t -> 'a t

=C2=A0 =C2=A0 let to_string =3D function
=C2=A0 =C2=A0 =C2=A0 | T t -> to_string t
=C2=A0 =C2=A0 =C2=A0 | x -> to_string x
=C2=A0 end

=C2=A0 let () =3D
=C2=A0 =C2=A0 print_endline @@ M1.to_string (M1.P (M1.T (M1.I 42), M1.S &qu= ot;foo"))


Is this sort of thing supposed to work?

Thanks,
Andre


--001a1146a00cb18cc0053f236c82--