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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 0013D7ED34 for ; Sun, 15 Jul 2012 20:58:42 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of darioteixeira@yahoo.com) identity=pra; client-ip=98.139.91.99; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="darioteixeira@yahoo.com"; x-sender="darioteixeira@yahoo.com"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of darioteixeira@yahoo.com) identity=mailfrom; client-ip=98.139.91.99; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="darioteixeira@yahoo.com"; x-sender="darioteixeira@yahoo.com"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@nm29.bullet.mail.sp2.yahoo.com) identity=helo; client-ip=98.139.91.99; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="darioteixeira@yahoo.com"; x-sender="postmaster@nm29.bullet.mail.sp2.yahoo.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlAEAJ4RA1Bii1tjaWdsb2JhbAA4DacfkTUNCRITBiSCGwUBAQQBCyAVAQIVFgQHAQEDCwYFRi8BDgEGEgaIEAEBAgYGBKkCCYJog3ABIwMBIwOJUQEGCgEBkTYDiEuMd4VPLU2IWoNb X-IronPort-AV: E=Sophos;i="4.77,588,1336341600"; d="scan'208";a="166928240" Received: from nm29.bullet.mail.sp2.yahoo.com ([98.139.91.99]) by mail1-smtp-roc.national.inria.fr with SMTP; 15 Jul 2012 20:58:41 +0200 Received: from [98.139.91.66] by nm29.bullet.mail.sp2.yahoo.com with NNFMP; 15 Jul 2012 18:58:40 -0000 Received: from [98.139.91.7] by tm6.bullet.mail.sp2.yahoo.com with NNFMP; 15 Jul 2012 18:58:40 -0000 Received: from [127.0.0.1] by omp1007.mail.sp2.yahoo.com with NNFMP; 15 Jul 2012 18:58:40 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 944157.90622.bm@omp1007.mail.sp2.yahoo.com Received: (qmail 58265 invoked by uid 60001); 15 Jul 2012 18:58:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1342378720; bh=cc1fq5mx4ZainQrG6nnbPq3eDEy1VTEt+i/vjfFbQUM=; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=cdyci2rn3+S59gNr1nz3tz8LrTlAYN4rN2Yn2GbyI04+larY0z1PZSdKs0I474crV27CzBjmuN/mwuOBaEU9VN90hPKWEhe1QbyNzCR2mQgx70vFAH41wKJUE4ZXN6PguG+UAmaAt2PYL+1BeLdn59VAGaqxxFQmzbYtORuWWwQ= DomainKey-Signature:a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=w39QSDPY5WJnrQGkLxRgj03iVaByJUh+2RD4XcLDJGm+RJ/vdYJr45j3E4IOIVUVPaX7qdNiaZwEYmpwE7bd9NhRpPSRVuKNKR4p0YgUoCzuiZD1F6xtWZsxCmycSYllYi8kk0sGbGilS5k8bvd2Nvd+TsJ5W3nHFVPiNP7r/BY=; X-YMail-OSG: NLrluoIVM1niR.NAx3rA8RM6oirZpiHFFgfSFurPC4ulISS dJiRn2OXct.x.2aHXUeq3CeNhCPX1p4tB1r6Lm6ShIlcCekpm2mxHpDwDq8Z VEJoE9XTR8RE1fxi0jLo0T2C_KB52Z9xMikff2TzyJl6UNOtwt8kt1h3xhQl Osw8udawHurQT5_ArNm2wSLBxEoQ8zawWBsO2Y2fgLNxL4sES7LZbcgYBSc3 d5oDfLTTbzoibx0eK7M_OitWgpM2jWo3CCMXSBt08wJGBQU.HWYsatMF1RIP GlGrYBV.mxxVMGnt3JcvL8IQysZkzlWrDlBZEu8Z0DdFFSqxpkiN.e62eMC0 hXQpUoZYaijuWNH1b3Lu7gNR_qCBHURdQZ.CcU588NsChtL09TRDUsU7rD9d VcnhPdpUP8wN.isPtekDzU8NpF.vvkQ79kLgeoOgxUhwOx.TGbc0bbd.lZUN JM0MYq.ST Received: from [195.23.39.96] by web111507.mail.gq1.yahoo.com via HTTP; Sun, 15 Jul 2012 11:58:40 PDT X-Mailer: YahooMailWebService/0.8.120.356233 References: <1342371289.7422.YahooMailNeo@web111511.mail.gq1.yahoo.com> Message-ID: <1342378720.56667.YahooMailNeo@web111507.mail.gq1.yahoo.com> Date: Sun, 15 Jul 2012 11:58:40 -0700 (PDT) From: Dario Teixeira Reply-To: Dario Teixeira To: Gabriel Scherer Cc: "caml-list@inria.fr" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] GADTs and parsers Hi, And thanks for the prompt reply! > I suspect the problem may be one of variance: you are using > polymorphic variants, but implicitly assuming that ([ `Nolink ] > inline_t) is a subtype of ([ `Nolink | `Link ] inline_t), which means > that "inline_t" is covariant in its first parameter. However, variance > of GADTs is currently very strict, and your inline_t definition is in > fact considered invariant (to check that, replace "type _ inline_t" by > "type (+'a) inline_t" and watch the error), so this conversion does > not pass. On the contrary, with a phantom type definition, the > parameter is inferred to be irrelevant (any variance is accepted), so > you can do whatever you want inside the abstraction boundary. Ah, indeed.=A0 And on a related note: is there a way to get the compiler to spill out the variance it infers?=A0 I'm assuming that 'ocamlc -i' does not include inferred variance because it is generally "obvious" and not something you usually have to worry about unless you want to make a type abstract.=A0 However, in a case like this it would help. (Or does the compiler *always* assume invariance with GADTs?) > (For more information on GADTs and variance, see the previous thread > on this on the mailing-list; the summary is that it's complicated, but > I still hope we could get something finer in the future. It would > probably not work with polymorphic variant instances, anyway.) In this case the use of polymorphic variants for the type parameter comes in handy because there is a subtyping relation and the [> ] declaration allows for useful mixing: # let x1 =3D Text "ola";; val x1 : [> `Nonlink ] inline_t =3D Text "ola" # let x2 =3D Link "lnk";; val x2 : [> `Link ] inline_t =3D Link "lnk" # let xs =3D [x1; x2];; val xs : [> `Link | `Nonlink ] inline_t list =3D [Text "ola"; Link "lnk"] Cheers, Dario