From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id C8983BBC1 for ; Wed, 12 Mar 2008 23:56:51 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgQCAKn810fAXQImh2dsb2JhbACQcQEBAQgKKY9AhyA X-IronPort-AV: E=Sophos;i="4.25,490,1199660400"; d="scan'208";a="9357505" Received: from discorde.inria.fr ([192.93.2.38]) by mail1-smtp-roc.national.inria.fr with ESMTP; 12 Mar 2008 23:56:51 +0100 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m2CMupjF022570 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 12 Mar 2008 23:56:51 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqQBANb810dA6ba4kmdsb2JhbACQcQEBAQEHBAQJChaPRIcg X-IronPort-AV: E=Sophos;i="4.25,490,1199660400"; d="scan'208";a="23696202" Received: from nf-out-0910.google.com ([64.233.182.184]) by mail4-smtp-sop.national.inria.fr with ESMTP; 12 Mar 2008 23:56:50 +0100 Received: by nf-out-0910.google.com with SMTP id g13so1500667nfb.7 for ; Wed, 12 Mar 2008 15:56:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=t3im+fvJh/vCqBGD7m6V+eSZ8HALWei+NnAEzMkvgZM=; b=vIpHOoNhRGtNSuugiUJpqsz8/41m+TUNMZm9d4ovKsOA4IJYoKtr+3qTeZHl8yVzBK59CViAGsLiSfMWx8JsBxh+2qU73kZb3AMN4O5cb3QYIvRVTIizUCwtSWJzT2VU2uQo9WHS4ZvmrM/xzC/ozl0jhUF7v1Y580WXGMrzAT4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=AJr13gWAN13vTGz6+avPv/eXtHSqsbqWdU0Df2FI/PrgLndvdisyD6WVEYhBw3W2e61fAG8ByaE12ifcTEOs4CQ8cm0iST6C7aXpXLhydy438Zb0vDRkU5ru3eSa2fyQibDddDSltmSyYprfPC7fc1eEBS418z0ns7vhXDQ16JU= Received: by 10.78.170.6 with SMTP id s6mr23741559hue.58.1205362609556; Wed, 12 Mar 2008 15:56:49 -0700 (PDT) Received: by 10.78.15.19 with HTTP; Wed, 12 Mar 2008 15:56:49 -0700 (PDT) Message-ID: <95513600803121556h79a845e7qfa756c36e4281154@mail.gmail.com> Date: Wed, 12 Mar 2008 23:56:49 +0100 From: "Olivier Andrieu" Sender: oandrieu@gmail.com To: "Richard Jones" Subject: Re: [Caml-list] Yet another question about insufficient polymorphism Cc: caml-list@inria.fr In-Reply-To: <20080312221335.GA16935@annexia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20080312193431.GA10622@annexia.org> <95513600803121319y508923a1vb36ac59c21e93f5b@mail.gmail.com> <20080312205911.GA14545@annexia.org> <95513600803121457l17e90817y54d419784462ae85@mail.gmail.com> <20080312221335.GA16935@annexia.org> X-Google-Sender-Auth: 1a3e3f81daa2d3ad X-Miltered: at discorde with ID 47D85FB3.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; andrieu:01 oandrieu:01 polymorphism:01 0100,:01 andrieu:01 0100,:01 -'a:01 covariance:01 val:01 val:01 coercions:01 -'a:01 omitting:01 variants:01 textbox:98 On Wed, Mar 12, 2008 at 11:13 PM, Richard Jones wrote: > [Hope you don't mind this but I've CC'd back to caml-list ...] > > > On Wed, Mar 12, 2008 at 10:57:46PM +0100, Olivier Andrieu wrote: > > On Wed, Mar 12, 2008 at 9:59 PM, Richard Jones wrote: > > > On Wed, Mar 12, 2008 at 09:19:32PM +0100, Olivier Andrieu wrote: > > > > aren't you missing a variance annotation ? like : > > > > > > > > type -'a component > > > > > > I don't know because no one has ever been able to explain covariance & > > > contravariance to me in a comprehensible way ! > > > > there's this post where I tried to explain that to someone: > > http://groups.google.com/group/fa.caml/msg/584ea2139b69f0ed > > > > > I added the '-' but it doesn't appear to have fixed the problem > > > unfortunately. > > > > You'll need it anyway I think :) > > What's the type of your functions that create components ? (textbox > > and button ?) > > val button : int -> int -> string -> [ `Button | `Component ] component > > val textbox : int -> int -> int -> int -> flag list -> > [ `Component | `Textbox ] component > > > > > Someone mentioned that it might be because when I added the signature, > > > the type became abstract (before, the implementation of the type was > > > exposed). I can't make that work either though, but maybe because my > > > type is slightly different than it was before ... > > > > You'll probably have to add some coercions , like: > > > > let as_co c = (c :> [`Component] component) > > > > and then > > > > form_add_components form [as_co text; as_co b1; as_co b2]; > > Right, this is very confusing. Adding the -'a annotation: > > type -'a component > > and: > > let as_co c = (c :> [`Component] component) in > > form_add_components form [as_co text; as_co b1; as_co b2]; > > works. > > However omitting the minus in "type -'a ..." breaks it, Right. The '-' annotation says the parameter is contravariant which means that with a coercion you can "loose" some of the variants. Without the annotation the coercion would fail. > and changing the list to: > > ([text; b1; b2] :> [`Component] component list) > > doesn't work either. Yes because it doesn't even get to the coercion, it fails while trying to build the list: text and b1 have incompatible types. In the end, the easiest way to write this is probably to avoid the list altogether: form_add_component form text ; form_add_component form b1 ; form_add_component form b2 ; -- Olivier