From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 5EB6A7FADE for ; Fri, 21 Nov 2014 21:48:04 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of lpw25@cam.ac.uk) identity=pra; client-ip=131.111.8.152; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="lpw25@cam.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of lpw25@cam.ac.uk) identity=mailfrom; client-ip=131.111.8.152; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="lpw25@cam.ac.uk"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@ppsw-52.csi.cam.ac.uk) identity=helo; client-ip=131.111.8.152; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lpw25@cam.ac.uk"; x-sender="postmaster@ppsw-52.csi.cam.ac.uk"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvcBAN+jb1SDbwiYnGdsb2JhbABCGoNjWYMGtFEGlECGawKBBRYBAQEBAREBAQEBAQgLCQkULoQDAQEDASMEUgULCQIaAgUhAgIPAQQNPBOILAMJCQQJOJkrnHuQQA1YhWoLAQEBHoEthQ2IFIIKMweCeYFVBZdJhR2CFIFzjieKdngBgkoBAQE X-IPAS-Result: AvcBAN+jb1SDbwiYnGdsb2JhbABCGoNjWYMGtFEGlECGawKBBRYBAQEBAREBAQEBAQgLCQkULoQDAQEDASMEUgULCQIaAgUhAgIPAQQNPBOILAMJCQQJOJkrnHuQQA1YhWoLAQEBHoEthQ2IFIIKMweCeYFVBZdJhR2CFIFzjieKdngBgkoBAQE X-IronPort-AV: E=Sophos;i="5.07,432,1413237600"; d="scan'208";a="89937756" Received: from ppsw-52.csi.cam.ac.uk ([131.111.8.152]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 21 Nov 2014 21:47:46 +0100 X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Received: from host86-175-178-49.range86-175.btcentralplus.com ([86.175.178.49]:46765 helo=study.localdomain) by ppsw-52.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.159]:587) with esmtpsa (PLAIN:lpw25) (TLSv1.2:AES128-GCM-SHA256:128) id 1Xrv7a-0008WG-F1 (Exim 4.82_3-c0e5623) (return-path ); Fri, 21 Nov 2014 20:48:02 +0000 From: Leo White To: Ashish Agarwal Cc: Caml List References: X-Face: "XWxb[u_Z\PA_Y?9@|IA!!+jTb(/290-*ea/Un$I0B98.$n%eL.;2w*,z]WR#T:,p[ NBd++M7l]#7zj7!{~iw $W-"/=|dVjhT[D{4~gE}gK<2`.6fs!;uqqud]vs2N/3^m7{aS1V, Date: Fri, 21 Nov 2014 21:04:48 +0000 In-Reply-To: (Ashish Agarwal's message of "Fri, 21 Nov 2014 13:39:09 -0500") Message-ID: <877fyoi7tb.fsf@study.localdomain> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] OR-patterns with GADTs Ashish Agarwal writes: > The following works fine: > > type foo > type bar > type _ t =3D > | Foo : string -> foo t > | Bar : string -> bar t > > let to_string : type a . a t -> string =3D function > =C2=A0 | Foo x -> x > =C2=A0 | Bar x -> x > > However, if you try to avoid the redundant code of the two branches, you = get a compile error: > > let to_string : type a . a t -> string =3D function > =C2=A0 | Foo x > =C2=A0 | Bar x -> x > > Error: This pattern matches values of type foo t > =C2=A0 =C2=A0 =C2=A0 =C2=A0but a pattern was expected which matches value= s of type a t > =C2=A0 =C2=A0 =C2=A0 =C2=A0Type foo is not compatible with type a > > Is there a real reason for this? I think the reason is that full support for or-patterns with GADTs is difficult. Matching on one GADT pattern generates one set of equations and matching on the other generates a different set of equations and you then need to check the body under the (parts of the) equations that are in both patterns. There might be something simpler than full support which wouldn't be that hard, but its not clear what that would be, so at the moment things just fail if you use GADTs in an or-pattern. There is a Mantis issue for it (http://caml.inria.fr/mantis/view.php?id=3D5736), so hopefully it will be resolved one day. Regards, Leo