Questions about class types

Christian Boos (boos@arthur.u-strasbg.fr)
Thu, 21 Nov 1996 18:10:27 +0100

Date: Thu, 21 Nov 1996 18:10:27 +0100
Message-Id: <199611211710.SAA08291@arthur.u-strasbg.fr>
From: Christian Boos <boos@arthur.u-strasbg.fr>
To: Hendrik Tews <tews@tcs.inf.tu-dresden.de>
Subject: Questions about class types
In-Reply-To: <199611211357.OAA10366@ithif18.inf.tu-dresden.de>

Hello,

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 ?

> The first idea is to implement f as an instance variable (of
> functional type) as well, but this gets very ugly as soon as
> there are some mutually recursive f's.

But this helps in some cases !

> The next idea was to specify only a type and some
> functionality, not a class ie:
>

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

module type A' = sig
val newb : unit -> < init : unit >
end

module B' : A' =
struct
class b () as self =
val a = ()
method init = self#f
method f = a
end

let newb () = (new b () :> < init : unit >)
end

This compiles fine !

-- Christian