From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA25736; Wed, 6 Aug 2003 18:12:30 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA24242 for ; Wed, 6 Aug 2003 18:12:28 +0200 (MET DST) Received: from mail.speakeasy.net (mail13.speakeasy.net [216.254.0.213]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h76GCQT12717 for ; Wed, 6 Aug 2003 18:12:27 +0200 (MET DST) Received: (qmail 11256 invoked from network); 6 Aug 2003 16:12:24 -0000 Received: from unknown (HELO grace.speakeasy.org) ([216.254.0.2]) (envelope-sender ) by mail13.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 6 Aug 2003 16:12:24 -0000 Date: Wed, 6 Aug 2003 09:12:24 -0700 (PDT) From: brogoff@speakeasy.net To: Richard Jones cc: David Brown , Vovka , "caml-list@inria.fr" Subject: Re: [Caml-list] static class member.... In-Reply-To: <20030806151051.GB29704@redhat.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Loop: caml-list@inria.fr X-Spam: no; 0.00; brogoff:01 caml-list:01 foo:01 struct:01 incr:01 0400,:01 newbie:01 freshmeat:01 autoconf:01 automake:01 compiles:01 rpms:01 bug:01 faq:01 beginner's:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Yes, it says in the language introduction (the part on objects) Let-bindings within class definitions are evaluated before the object is constructed so using a class local let bound ref works if you want the member to be unique on a per class basis. If you'd like the counter to apply to a class and everything that inherits from it, then you use module level let's like so module Foo = struct let counter = ref 0 class c = object method get () = !counter method bump () = incr counter end end;; A non-orthogonality of the let within a class is that let module isn't permitted. Is there any reason it isn't? As a side advice to the OP, it would be worthwhile to avoid the OOP and just get used to the ML part of Caml first. -- Brian On Wed, 6 Aug 2003, Richard Jones wrote: > On Wed, Aug 06, 2003 at 07:51:48AM -0700, David Brown wrote: > > On Wed, Aug 06, 2003 at 03:45:23PM +0100, Richard Jones wrote: > > > On Wed, Aug 06, 2003 at 04:57:26PM +0400, Vovka wrote: > > > > Hi!!!! > > > > > > > > Could you help me please. I'm newbie in ocaml programming, i used to write > > > > programmes in C++ , so I've faced difficulties in introducing static > > > > class member(==a common member for all objects of the same class). Can i > > > > handle it in ocaml? Thanks a lot. > > > > > > This is one way to do it, there might be other easier ways: > > > > > > class foo = > > > let counter = ref 0 in > > > > But this counter will be unique for each new instance of the class. > > Not so. Run my code & you'll see it works. > > Rich. > > -- > Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj > Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you. > MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles, > RPMs, pkgs etc. Linux, BSD, Solaris. http://www.annexia.org/freeware/makeplus/ > > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr > Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners