From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p1M7EaA8017053 for ; Tue, 22 Feb 2011 08:14:36 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoQBAH7xYk1V2gB5mWdsb2JhbACmWAEBAQEBCAsKBxEku1kNhVEEj2g X-IronPort-AV: E=Sophos;i="4.62,206,1297033200"; d="scan'208";a="91778213" Received: from emailfrontal2.citycable.ch ([85.218.0.121]) by mail2-smtp-roc.national.inria.fr with SMTP; 22 Feb 2011 08:14:31 +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 9354B8340CB; Tue, 22 Feb 2011 08:14:25 +0100 (CET) Received: from yziquel by seldon with local (Exim 4.72) (envelope-from ) id 1PrbP9-0001Cb-0D; Mon, 21 Feb 2011 20:26:43 +0100 Date: Mon, 21 Feb 2011 20:26:42 +0100 From: Guillaume Yziquel To: Dario Teixeira Cc: caml-list@inria.fr Message-ID: <20110221192642.GK25151@localhost> References: <20110221170702.GJ25151@localhost> <982043.53335.qm@web111502.mail.gq1.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <982043.53335.qm@web111502.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 p1M7EaA8017053 Subject: Re: [Caml-list] Constraining abstract type to be of a given subtype Le Monday 21 Feb 2011 à 10:42:43 (-0800), Dario Teixeira a écrit : > Hi, > > > 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. > > Perhaps I am indeed pushing the module language beyond its design > intentions, but my requirement does not strike me as completely > unreasonable... > > If I get rid of the constraint altogether, then I lose the guarantee that > kind_t is a subtype of Kind.t. But if I declare kind_t = Kind.t in the > signature FOO, then I lose the ability to declare particular instances > of FOO to be more *tightly* constrained than the generic Kind.t. > > Any further ideas on how I may be able to have my cake and eat it too? > > Cheers, > Dario Teixeira I think it's going to be tough. The closest I've come to is: # module type Q = sig type 'a t end;; module type Q = sig type 'a t end # module type W = Q with type 'a t = [< `A | `B] as 'a;; Error: In this `with' constraint, the new definition of t does not match its original definition in the constrained signature: Type declarations do not match: type 'a t = 'a constraint 'a = [< `A | `B ] is not included in type 'a t Their constraints differ. While it is possible to 'specialise' a type in a module type signature, it seems unlikely that it is possible to 'specialise' constraints to narrower constraints. -- Guillaume Yziquel