Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Hendrik Tews <tews@irritatie.cs.kun.nl>
To: caml-list@inria.fr
Subject: Re: initialization of instance variables
Date: Sat, 3 Apr 1999 12:40:56 +0200	[thread overview]
Message-ID: <199904031040.MAA07271@irritatie.cs.kun.nl> (raw)
In-Reply-To: <14083.34604.727325.126299@hadar.cse.Buffalo.EDU>


John Whitley writes:
   
   While the let-bound version works, it seems to obfuscate the intent,
   which was to have an instance variable called 'x'.  It also means that
   a subclass inheriting foo' cannot reuse or redefine x.
   
I have two remarks about that:

1. IMO the intent of your example is that a complicated function
is computed just before object creation. I think this is best
captured by the let construction. Alternatively you could use
initializers and exploit late binding in the computation of the
complicated function.

2. You can still have an instance variable x:

   (* make initial computation _very_ explicit *)

   class foo' input =
   let x_init = complicated_function input in
   let y_init = another function x_init    in
   object
     val x = x_init
     val y = y_init
     (* those imaginary methods again... *)
   end


Bye,

Hendrik




      reply	other threads:[~1999-04-06  6:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-27 18:04 John Whitley
1999-04-01 13:10 ` Jerome Vouillon
1999-04-01 15:01   ` John Whitley
1999-04-03 10:40     ` Hendrik Tews [this message]

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=199904031040.MAA07271@irritatie.cs.kun.nl \
    --to=tews@irritatie.cs.kun.nl \
    --cc=caml-list@inria.fr \
    /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