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 p2HB7TvF010110 for ; Thu, 17 Mar 2011 12:07:29 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArUJALqHgU1V2gB5Zmdsb2JhbAClYQ0LCQgVJcQ2DYVWBJBF X-IronPort-AV: E=Sophos;i="4.63,198,1299452400"; d="scan'208";a="94314830" Received: from emailfrontal2.citycable.ch ([85.218.0.121]) by mail2-smtp-roc.national.inria.fr with SMTP; 17 Mar 2011 12:07:24 +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 2F1618345B3; Thu, 17 Mar 2011 12:07:21 +0100 (CET) Received: from yziquel by seldon with local (Exim 4.72) (envelope-from ) id 1Q0B1c-0003wH-H4; Thu, 17 Mar 2011 12:05:52 +0100 Date: Thu, 17 Mar 2011 12:05:52 +0100 From: Guillaume Yziquel To: Pierre-Alexandre Voye Cc: caml-list Message-ID: <20110317110552.GP22969@localhost> References: <20110317104719.GH22969@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: 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 p2HB7TvF010110 Subject: Re: [Caml-list] Re: Define class and sum type in one time Le Thursday 17 Mar 2011 à 11:50:37 (+0100), Pierre-Alexandre Voye a écrit : > So, this is impossible ?  : > class maclasse = object(self) >  val mutable valeur = (None : truc option) >  method getValeur = valeur > end > and > truc = Machin of (maclasse->int) | Recur of truc;; > ? > (three attempt to write a correct example of my problem.. All apologies > !) No, you can. Break the recursivity with a recursive module. However, it's quite clumsy, so if you do not have a compelling reason to use object, avoid the useless complexity. module rec M : sig class maclasse : object val mutable valeur : M.truc option method getValeur : M.truc option end type truc = Machin of (maclasse -> int) | Recur of truc end = struct class maclasse = object val mutable valeur : M.truc option = None method getValeur = valeur end type truc = Machin of (maclasse -> int) | Recur of truc end include M -- Guillaume Yziquel