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