From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA16390 for caml-redistribution; Thu, 26 Nov 1998 16:27:37 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA31142 for ; Wed, 25 Nov 1998 16:17:14 +0100 (MET) Received: from post.tepkom.ru (relay.tepkom.ru [195.9.240.162]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id QAA18946 for ; Wed, 25 Nov 1998 16:17:11 +0100 (MET) Received: from localhost (msk@localhost) by post.tepkom.ru (8.8.7/8.8.7) with ESMTP id SAA01263 for ; Wed, 25 Nov 1998 18:17:35 +0300 Date: Wed, 25 Nov 1998 18:17:35 +0300 (MSK) From: Anton Moscal To: caml-list@inria.fr Subject: Objects as sums In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis Hello! I try to write in O'Caml a well-known idiom of OO for simulating disjoint sum of types by virtual methods and inheritance: working example in C++: +++++++++ #include class B; class C; class A { public: virtual B * b () { abort (); return 0; } virtual C * c () { abort (); return 0; } }; class B { public: virtual B * b () { return this; } }; class C { public: virtual C * c () { return this; } }; -------- but, when I write the same program in O'Caml: ++++++++ class a = object (self) method b () = ((assert false): b) method c () = ((assert false): c) end and b = object (self) inherit a method b () = self end and c = object (self) inherit a method c () = self end ------- It doesn't work (with diagnostics `self type can't escape from it's scope'). The following question arises: either this idiom can't be expressed in O'Caml or I'm fool :) and is it possible to do it by any way? Regards, Anton E. Moscal