[
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: | Christian Boos <boos@a...> |
| Subject: | Questions about class types |
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