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 9E5317FADE for ; Fri, 21 Nov 2014 19:39:30 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of agarwal1975@gmail.com) identity=pra; client-ip=209.85.212.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="agarwal1975@gmail.com"; x-sender="agarwal1975@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of agarwal1975@gmail.com designates 209.85.212.178 as permitted sender) identity=mailfrom; client-ip=209.85.212.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="agarwal1975@gmail.com"; x-sender="agarwal1975@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-wi0-f178.google.com) identity=helo; client-ip=209.85.212.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="agarwal1975@gmail.com"; x-sender="postmaster@mail-wi0-f178.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApwBAByGb1TRVdSym2dsb2JhbABchDwEgwLRKQcWAQEBAQERAQEBAQEGCwsJFC6DeSIRBBkBGx4DEgMFAQc3AiQBEQEFASI1iAkBAxKZUI0ngyI9MYs7gXKDEYpEChknDWiGDQEFDpN4gVQFjBuSRpUAGCmFUx8wgksBAQE X-IPAS-Result: ApwBAByGb1TRVdSym2dsb2JhbABchDwEgwLRKQcWAQEBAQERAQEBAQEGCwsJFC6DeSIRBBkBGx4DEgMFAQc3AiQBEQEFASI1iAkBAxKZUI0ngyI9MYs7gXKDEYpEChknDWiGDQEFDpN4gVQFjBuSRpUAGCmFUx8wgksBAQE X-IronPort-AV: E=Sophos;i="5.07,432,1413237600"; d="scan'208";a="108892392" Received: from mail-wi0-f178.google.com ([209.85.212.178]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 21 Nov 2014 19:39:30 +0100 Received: by mail-wi0-f178.google.com with SMTP id hi2so161106wib.5 for ; Fri, 21 Nov 2014 10:39:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=roQwWnrYLmghcASBP2bcBUm0vt0LG73Rn+SQfhHYrvQ=; b=oSwSy8wpBvWqRju9TRwWuB5MwCpESr+kqMQdgZ57SRn1mAeF0nq54+CU5c4GHrOBrq wLTRbEDT+7u4RMz4c6FT/TYANqGLXCyXdqkCfCRvZZXihj8lQnNmXEiEb0ryMGSVC+M4 7v56ILZyi/tY8kS1LjYrsGCWuXqTGILdTVaB+Pgg2CbOyH/ESFDcSTsOHc4wgQ/noOrd aTw5/dbgXrAzKbKWhHluUsienr3GPvgZtqjkG3X1N/PjZy2t6cnFqpS1B11BEeE2dJ7n gdyWjWocHDZxkUDM+FrW9EZHDR54Nt1mvvqM6oVOWjgeZ4yDbGcF48a/AWbs7dYcdz2w XYnQ== X-Received: by 10.180.103.1 with SMTP id fs1mr177164wib.62.1416595169715; Fri, 21 Nov 2014 10:39:29 -0800 (PST) MIME-Version: 1.0 Received: by 10.27.5.203 with HTTP; Fri, 21 Nov 2014 10:39:09 -0800 (PST) From: Ashish Agarwal Date: Fri, 21 Nov 2014 13:39:09 -0500 Message-ID: To: Caml List Content-Type: multipart/alternative; boundary=f46d04428da8e1b3dd050862c30d Subject: [Caml-list] OR-patterns with GADTs --f46d04428da8e1b3dd050862c30d Content-Type: text/plain; charset=UTF-8 The following works fine: type foo type bar type _ t = | Foo : string -> foo t | Bar : string -> bar t let to_string : type a . a t -> string = function | Foo x -> x | 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 = function | Foo x | Bar x -> x Error: This pattern matches values of type foo t but a pattern was expected which matches values of type a t Type foo is not compatible with type a Is there a real reason for this? --f46d04428da8e1b3dd050862c30d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
The following works fine:

ty= pe foo
type bar
type _ t =3D
| Foo : string -= > foo t
| Bar : string -> bar t

le= t 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 branche= s, you get a compile error:

let to_string : t= ype a . a t -> string =3D function
=C2=A0 | Foo x
= =C2=A0 | Bar x -> x

Error: This patt= ern matches values of type foo t
=C2=A0 =C2=A0 =C2=A0 =C2=A0but a= pattern was expected which matches values 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?

--f46d04428da8e1b3dd050862c30d--