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 NAA12676; Fri, 11 Jan 2002 13:05:09 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA12610 for ; Fri, 11 Jan 2002 13:05:09 +0100 (MET) Received: from santenay.inria.fr (santenay.inria.fr [128.93.8.59]) by concorde.inria.fr (8.11.1/8.11.1) with SMTP id g0BC56P09268; Fri, 11 Jan 2002 13:05:06 +0100 (MET) Date: Fri, 11 Jan 2002 13:09:20 -0500 From: Maxence Guesdon To: Michael Vanier Cc: caml-list@inria.fr Subject: Re: [Caml-list] class variables? Message-Id: <20020111130920.338c2a9b.maxence.guesdon@inria.fr> In-Reply-To: <200201102343.g0ANh6706101@orchestra.cs.caltech.edu> References: <200201102343.g0ANh6706101@orchestra.cs.caltech.edu> Organization: INRIA X-Mailer: Sylpheed version 0.6.6 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Hi, > > I'm considering using ocaml for a project I'm planning. I plan to use the > object-oriented features of ocaml extensively. I was wondering: is there > any way to get immutable class fields that are shared by all members of the > class? I was thinking of a list of strings, and I don't want to have to > have the list duplicated for every instance of the class. You can do it this way : class foo = let my_list = [ "foo" ; "bar"] in object ... end let t = new foo let u = new foo Now t and u are too objects sharing the same list (my_list), like anyhting before the 'object' keyword. *But* if class foo has parameters, then the expressions before the 'objet' keyword are evaluated at each creation of a new instanciation, so in the following code class foo () = let my_list = [ "foo" ; "bar"] in object ... end let t = new foo let u = new foo t and u are two objects which don't share the list my_list. anybody please correct me if i'm wrong. -- Maxence Guesdon ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr