Re: Questions about class types

Hendrik Tews (tews@tcs.inf.tu-dresden.de)
Tue, 10 Dec 1996 12:10:50 +0100

Date: Tue, 10 Dec 1996 12:10:50 +0100
Message-Id: <199612101110.MAA11392@ithif18.inf.tu-dresden.de>
From: Hendrik Tews <tews@tcs.inf.tu-dresden.de>
Subject: Re: Questions about class types

Hello,

sorry for answering so late. I had some holidays at the end of
November.

Christian Boos wrote:

Hendrik Tews writes:
> ...
> Unfortunately B does not match A, because (as it is written in
> the documentation under 4.9.2) one can add additional instance
> variables, but no additional methods. What is the reason for
> this?

That's a good question. Maybe O'Caml will add private methods some day ?

I am not sure what you exactly mean by "private methods". I am
looking for means to distinguish different access privilegs to an
object. In a more realistic example (which uses more types than
just unit) one would implement a service through a couple of
objects. One of them would provide the interface of the service
to the outside world. But in a distributed environment it might
be useful to update the state of the interface object
asyncronously. Therefore the interface object needs some methods
in addition to the methods for the interface. (In C++ I would use
a friend directive in such a case)

In ocaml I could hide all the additional objects in a module
implementation. But so far it is not possible to hide methods via
signature matching.

This is a good idea. You're mistake was on using the ellipsis '..' which
doesn't seem to be needed in your example.

You are right. I don't need the ellipsis.

But I still don't understand the type error I got:

Values do not match:
val newb : unit -> b
is not included in
val newb : unit -> < init : unit; .. >

If b does not match < init : unit; .. > then the type cast in

# let newb () : < init : unit; .. > = ((new b ()) : < init : unit; .. >)

should produce an error. On the other side if the type cast is
valid, then the types should match.

Greetings,

Hendrik