Re: Questions about class types

Jerome Vouillon (vouillon@clipper.ens.fr)
Wed, 11 Dec 1996 14:16:31 +0100 (MET)

Date: Wed, 11 Dec 1996 14:16:31 +0100 (MET)
From: Jerome Vouillon <vouillon@clipper.ens.fr>
To: Hendrik Tews <tews@tcs.inf.tu-dresden.de>
Subject: Re: Questions about class types
In-Reply-To: <199612101110.MAA11392@ithif18.inf.tu-dresden.de>

Hello,

> 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.

It is definitively not possible to hide methods in a class. When a
method is redefined, it must keep the same type. The reason is that
other methods of the same class might invocate it, and thus expect it
to have a certain type. But if a method were hidden, its previous type
would also be hidden, and there would be no way to enforce a
redefinition of this method to have the right type.

> 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.

Type < init : unit; .. > is more general than type
b = < init : unit; f : unit > (the ellipsis is an unamed type
variable). So, your type cast produces no error (these two types can
be unified), but you cannot expect a function of type unit -> b to be
considered as having the more general type
unit -> < init : unit; .. >.

Regards,

Jerome