Browse thread
extending a functional updater implicitly publicizes sub-updater method?
[
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: | Marc Herbert <marc.herbert.1@m...> |
| Subject: | private methods restricted to self? |
On Tue, 22 Mar 2005, Remi Vanicat wrote:
> > I don't understand why my private subupdater is "made public implicitly"
> In ocaml, you can only call a private method on self. super#forward
> is not self, so you cannot call the color_forward method on it.
Indeed! This other example, without any subclass, is even more
surprising:
class functional_point =
object(self)
val x = 0
val y = 0
method private bump_x = {< x = x + 1 >}
method private bump_y = {< y = y + 1 >}
method private bump_both = self#bump_x#bump_y
end
Warning: the following private methods were made public implicitly:
bump_y
> In ocaml, you can only call a private method on self. super#forward
> is not self, so you cannot call the color_forward method on it.
Thanks a lot for the reasoning. But I still don't get the rationale.
Could I find the answer in Jerôme Vouillon's "an object calculus with
views"? Elsewhere? Thanks in advance.
About the reference documentation
---------------------------------
However ignorant are my questions above, I nevertheless think the
documentation is not clear about this whole issue.
To find this self#private restriction you have to dive into section
'6.9.2 Class expressions'. Unfortunately you may never go so far since
the more user-friendly '3.6 Private methods' section gives the less
restrive, more usual definition:
"Private methods are methods that do not appear in object
interfaces. They can only be invoked from other methods of the same
object."
which made me think I knew enough about 'private' and prevented me to
look further.
Section '6.9.1 class types' also states:
"The flag private indicates whether the method can be accessed from
outside the class."
Coming from another OO-language, it's hard to understand "outside" as
"restricted to self".
So as a conclusion I find the manual at least confusing on this, if
not erroneous. Is it?
By the way, maybe some extra comment in the Warning message above
would not hurt either.
--
So einfach wie möglich. Aber nicht einfacher -- Albert Einstein