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 p2IHHEQK027001 for ; Fri, 18 Mar 2011 18:17:14 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApACAGowg03U4367kWdsb2JhbACERKEqFQEBAQkLCwcUAyKITakMkGkCgSWDRXcEiCKIEA X-IronPort-AV: E=Sophos;i="4.63,206,1299452400"; d="scan'208";a="78663726" Received: from moutng.kundenserver.de ([212.227.126.187]) by mail3-smtp-sop.national.inria.fr with ESMTP; 18 Mar 2011 18:17:09 +0100 Received: from office1.lan.sumadev.de (dslb-094-219-213-188.pools.arcor-ip.net [94.219.213.188]) by mrelayeu.kundenserver.de (node=mreu4) with ESMTP (Nemesis) id 0Mfwsi-1QNmsa1eBI-00N6Hv; Fri, 18 Mar 2011 18:17:08 +0100 Received: from [192.168.1.111] (546BE640.cm-12-4d.dynamic.ziggo.nl [84.107.230.64]) by office1.lan.sumadev.de (Postfix) with ESMTPA id 993E65F702; Fri, 18 Mar 2011 18:17:02 +0100 (CET) From: Gerd Stolpmann To: Pierre-Alexandre Voye Cc: caml-list In-Reply-To: References: <20110317104719.GH22969@localhost> Content-Type: text/plain; charset="UTF-8" Date: Fri, 18 Mar 2011 18:16:59 +0100 Message-ID: <1300468619.8429.8.camel@thinkpad> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 X-Provags-ID: V02:K0:YAwvJ8bwra75GbPWamSu0uekYoLE6EZa6NvmZWzOi4E HNrlEhXfikytAGe1jd56DIUOK4dmB/DeUvEkojMQZeEIIpKw6V URiqye2/0Tp0vNhOcdVXmmFqaXGwX9zRYFC/fxf7Z06OAQ6GN1 EHWPA/yy7oeUjgu2jC1MiIooDtOwtXC+J1TKckrCTbu8rvAvSd W3uCd5BQUZob026l4k2Uw== Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p2IHHEQK027001 Subject: Re: [Caml-list] Re: Define class and sum type in one time Am Donnerstag, den 17.03.2011, 11:50 +0100 schrieb Pierre-Alexandre Voye: > 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 !) This is the closest without introducing a type variable: type maclasse_t = < getValeur : truc option > and truc = Machin of maclasse_t->int | Recur of truc Here, maclasse is just an object type (which is less than a full class type, as it has only methods but no type information about instance variables). In a second step you can define the class: class maclasse = ( object ... end : maclasse_t ) Generally, it is a good recommendation to define object or class types before doing the class implementation. Not only allows it more complicated types but it is also easier to get the typing right, because you have always maclasse_t at hand to give type hints. Gerd > > 2011/3/17 Guillaume Yziquel > Le Thursday 17 Mar 2011 à 11:33:44 (+0100), Pierre-Alexandre > Voye a écrit : > > My example would be better with this : > > class machin = object(self) > > > Â val mutable valeur = (None : truc option) > > Â method getValeur = valeur > > end > > and > > truc = Machin of (int->int) | Recur of truc;; > > The object need the type defined > > > You cannot declare a class and a type with an 'and'. Either > two classes, > or two types. > > Simply declare truc before machin. > > type truc = Machin of int -> int | Recur of truc > > class machin = object > > val mutable valeur : truc option = None > > method getValeur = valeur > > end > > -- > Guillaume Yziquel > > > > -- > --------------------- > Isaac Project - http://www.lisaac.org/ -- ------------------------------------------------------------ Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de Phone: +49-6151-153855 Fax: +49-6151-997714 ------------------------------------------------------------