caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Maxence Guesdon <maxence.guesdon@inria.fr>
To: Michael Vanier <mvanier@cs.caltech.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] class variables?
Date: Fri, 11 Jan 2002 13:09:20 -0500	[thread overview]
Message-ID: <20020111130920.338c2a9b.maxence.guesdon@inria.fr> (raw)
In-Reply-To: <200201102343.g0ANh6706101@orchestra.cs.caltech.edu>


> 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


  parent reply	other threads:[~2002-01-11 12:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-10 23:43 Michael Vanier
2002-01-11 11:40 ` Warp
2002-01-11 18:09 ` Maxence Guesdon [this message]
2002-01-11 12:19   ` Alain Frisch
2002-01-11 12:25   ` Andreas Rossberg
2002-01-11 20:39     ` Michael Vanier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020111130920.338c2a9b.maxence.guesdon@inria.fr \
    --to=maxence.guesdon@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=mvanier@cs.caltech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).