David Chemouil <David.Chemouil@enseeiht.fr> writes:
> I've been using the OO features of Caml these past days, and soon
> observed a behavior of the typing system that I don't understand. Here
> is a simplified version of my problem:
>
> # 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 (which is possible in Java or Eiffel for example). Could
> someone explain me? Or is there a paper talking about this?
The problem is that you're using self during the initialization of the
object, not in a method of the object. Since the object isn't yet
initialized, it can't be passed to functions. If you use a method,
you're okay:
class a (arg : a -> b) =
object (self)
method ob = arg self
end
and b =
object
end
John.
This archive was generated by hypermail 2b29 : Fri Mar 10 2000 - 09:04:05 MET