Date: Sat, 3 Apr 1999 12:40:56 +0200
Message-Id: <199904031040.MAA07271@irritatie.cs.kun.nl>
From: Hendrik Tews <tews@irritatie.cs.kun.nl>
To: caml-list@inria.fr
Subject: Re: initialization of instance variables
In-Reply-To: <14083.34604.727325.126299@hadar.cse.Buffalo.EDU>
<19990401151014.56489@pauillac.inria.fr>
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
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:21 MET