Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Base class "constructor" being called multiple times?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: Re: "ocaml_beginners"::[] Base class "constructor" being called multiple times?
> so the call to print_endline is done when the class is define, not
> when the object is created. 

Ah, interesting.

So I have another question about this code:

class base =
let t = 0 in
object (self)
val obj = t
method obj = obj

class derived =
object (self)
inherit base

class contains =
object (self)
inherit derived

method add (w : #derived) = Printf.printf "contains: %d\n" w#obj

I want the contains#add method to have the following signature:

#derived -> unit

meaning that it can only be applied to class 'derived' (and
subclasses). It would be a mistake to call add with a 'base'.

However, the above code doesn't compile, and gives a pretty strange

File "", line 13, characters 5-128:
Some type variables are unbound in this type:
class contains :
object val obj : int method add : #derived -> unit method obj : int end
The method add has type #derived -> unit where .. is unbound

What does the '..' mean?


Richard Jones.
Merjis Ltd. - all your business data are belong to you.
"I wish more software used text based configuration files!"
-- A Windows NT user, quoted on Slashdot.