From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p1LH91jl018398 for ; Mon, 21 Feb 2011 18:09:01 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AokBAIIqYk1V2gB5mWdsb2JhbACmPwEBAQEBCAsKBxEkuw4NhVEEj2g X-IronPort-AV: E=Sophos;i="4.62,201,1297033200"; d="scan'208";a="76316091" Received: from emailfrontal2.citycable.ch ([85.218.0.121]) by mail3-smtp-sop.national.inria.fr with SMTP; 21 Feb 2011 18:08:56 +0100 X-Alinto-smtpauth-localdomain: Yes Received: from seldon (unknown [85.218.93.111]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal2.citycable.ch (Postfix) with ESMTPA id A56228340D6; Mon, 21 Feb 2011 18:08:54 +0100 (CET) Received: from yziquel by seldon with local (Exim 4.72) (envelope-from ) id 1PrZDz-0003Fx-Q3; Mon, 21 Feb 2011 18:07:03 +0100 Date: Mon, 21 Feb 2011 18:07:03 +0100 From: Guillaume Yziquel To: Dario Teixeira Cc: caml-list@inria.fr Message-ID: <20110221170702.GJ25151@localhost> References: <241708.48122.qm@web111501.mail.gq1.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <241708.48122.qm@web111501.mail.gq1.yahoo.com> User-Agent: Mutt/1.5.20 (2009-06-14) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p1LH91jl018398 Subject: Re: [Caml-list] Constraining abstract type to be of a given subtype Le Monday 21 Feb 2011 à 07:56:43 (-0800), Dario Teixeira a écrit : > Hi, > > In a signature FOO, I'm trying to constrain an abstract type kind_t to be a > subtype of Kind.t (please see code below). However, I get a compiler error > when I declare an actual struct Foo1 which supposedly obeys signature FOO: > > Type declarations do not match: > type 'a kind_t = [ `A ] > is not included in > type 'a kind_t = 'a constraint 'a = [< Kind.t ] > > > Any hints as to what is wrong here? Thanks in advance for your help! Well, I clearly see to what 'a is bound to in type 'a kind_t = 'a constraint 'a = [< Kind.t ] but I do not see to what 'a is bound to in type 'a kind_t = [ `A ] As 'a kind_t is declared to be 'a in the first type declaration, it should also be the case in the second type declaration. However, 'a is a phantom type parameter there. > Best regards, > Dario Teixeira But I think that you will not be able to do such type narrowing in a module interface / module interface fashion. At least not without an indication of covariance or contravariance. And even then, I'm not sure if that is possible. -- Guillaume Yziquel