Version française
Home     About     Download     Resources     Contact us    
Browse thread
initialization of instance variables
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Whitley <whitley@c...>
Subject: Re: initialization of instance variables
Jerome Vouillon writes:
 > It would actually be quite easy to allow the use of an instance
 > variable in the following instance variable definitions.  The reason
 > it is not allowed for the moment is that I think it may be a bit
 > confusing. [discussion elided]

Ah, indeed!  That hadn't occured to me offhand, probably as the
code that elicited this question uses immutable instance variables.

In my code, the alternative of using let bindings seemed
counter-intuitive:

(* prohibited form *)
class foo input =
object
  val x = complicated_function input
  val y = another_function x
  (* imagine some methods... *)
end

(* a working, let-bound form *)
class foo' input =
let x = complicated_function input in
object
  val y = another function x
  (* those imaginary methods again... *)
end


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.


Thanks much,
John