David Chemouil <David.Chemouil@enseeiht.fr> writes:
> # class a (arg : a -> b) = object(self)
> val ob = arg self
> end
> and b = object
> end;;
>
> The instance variable self
> cannot be accessed from the definition of another instance variable
> I don't understand why it is forbidden for an object to pass itself to
> another one
Indeed, this is unsafe, since the function arg could well try to access
the field "ob" of self that you are currently trying to initialize (so this
is not done yet).
Consider, for instance,
class a = object (self) val ob = self#bad method bad = ob + 1 end;;
which is very similar to:
type a = { ob : int; }
let rec self = { ob = self.ob + 1; };;
> (which is possible in Java or Eiffel for example).
Yes, but unfortunately Java is not a reference. In particular, it
initializes all fields to meaningless default values (which will often
result in a dynamically-raised null-pointer exception).
Didier
This archive was generated by hypermail 2b29 : Fri Mar 10 2000 - 09:15:03 MET