Browse thread
typing of a class
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Xavier Leroy <Xavier.Leroy@i...> |
| Subject: | Re: typing of a class |
David Chemouil 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
> > (which is possible in Java or Eiffel for example).
You can write your example just like in Java, by 1- making the
instance variable mutable, and 2- using an option type to play the
role of Java's null pointers. You'd get:
class a arg = object(self)
val mutable ob = (None : b option)
initializer ob <- Some(arg self)
end;;
It's not pretty, but that's exactly what's going on "under the hood"
in the equivalent Java code.
- Xavier Leroy