From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p1ILa6XS017177 for ; Fri, 18 Feb 2011 22:36:11 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AloBAId1Xk1V2gB4mWdsb2JhbACmPgEBAQEBCAsKBxEkuyMNhVEEj2U X-IronPort-AV: E=Sophos;i="4.62,189,1297033200"; d="scan'208";a="100221571" Received: from emailfrontal1.citycable.ch ([85.218.0.120]) by mail1-smtp-roc.national.inria.fr with SMTP; 18 Feb 2011 22:35:49 +0100 X-Alinto-smtpauth-localdomain: Yes Received: from seldon (unknown [85.218.93.111]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal1.citycable.ch (Postfix) with ESMTPA id 134B212C0F5; Fri, 18 Feb 2011 22:35:48 +0100 (CET) Received: from yziquel by seldon with local (Exim 4.72) (envelope-from ) id 1PqXyJ-0001lv-79; Fri, 18 Feb 2011 22:34:39 +0100 Date: Fri, 18 Feb 2011 22:34:39 +0100 From: Guillaume Yziquel To: Jean-Louis Giavitto Cc: caml-list@inria.fr Message-ID: <20110218213439.GA4106@localhost> References: <4D5ECD89.6060906@ircam.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <4D5ECD89.6060906@ircam.fr> 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 p1ILa6XS017177 Subject: Re: [Caml-list] Contraintes dans la =?ISO-8859-1?Q?d=E9finitionr=E9cursiv?=e de classes Le Friday 18 Feb 2011 à 20:50:33 (+0100), Jean-Louis Giavitto a écrit : > Bonjour. > > Je rencontre le problème suivant : une définition récursive de > classe contraint les types paramètres de la classe, plus que je ne > le souhaiterais. > > Je ne comprend pas d'où viennent ces contraintes supplémentaires. > Voici un exemple minimal : > > class virtual ['a, 'b] base = > object > method virtual m : 'a -> 'b derive > end > > and virtual ['a] derive = > object > inherit ['a, 'a] base > end A solution might be to break the recursive definition and the class and push it to a module level. You should probably be able to use recursive modules to make "forward declarations". yziquel@seldon:~$ ocaml Objective Caml version 3.12.0 # module rec M : sig class virtual ['a, 'b] base : object method virtual m : 'a -> 'b M.derive end class virtual ['a] derive : object inherit ['a, 'a] base end end = M;; module rec M : sig class virtual ['a, 'b] base : object method virtual m : 'a -> 'b M.derive end class virtual ['a] derive : object method virtual m : 'a -> 'a M.derive end end # -- Guillaume Yziquel