From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA06227; Tue, 22 Jan 2002 18:26:28 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA05998 for ; Tue, 22 Jan 2002 18:26:27 +0100 (MET) Received: from CS.UniBO.IT (leporello.cs.unibo.it [130.136.1.110]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g0MHQQf19326 for ; Tue, 22 Jan 2002 18:26:26 +0100 (MET) Received: from marcello.cs.unibo.it (root@marcello.cs.unibo.it [130.136.2.29]) by CS.UniBO.IT (8.9.3/8.9.3/Debian 8.9.3-6) with ESMTP id SAA15065 for ; Tue, 22 Jan 2002 18:26:22 +0100 Received: (from sacerdot@localhost) by marcello.cs.unibo.it (8.9.3/8.9.3/Debian 8.9.3-21) id SAA08123 for caml-list@inria.fr; Tue, 22 Jan 2002 18:26:21 +0100 Date: Tue, 22 Jan 2002 18:26:21 +0100 From: Claudio Sacerdoti Coen To: caml-list@inria.fr Subject: [Caml-list] Hiding public methods/friends methods Message-ID: <20020122182621.B8021@cs.unibo.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i X-Operating-System: Debian GNU/Linux X-Organization: Department of computer science, University of Bologna, Eurpean Union Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, I would like to define a huge bunch of mutual recursive classes with "friends methods". (The code is automatically generated, so I don't mind very much an heavy coding style.) Of course, I can use the trick of abstracting the output type of all the friends methods in the signature of the module. Because I have lots of friends methods, though, the resulting .mli I get is quite confusing. Another solution is creating "proxy" objects (see the code below). But I fear the performance loss to be significant. Which solution is best (not withstanding performances) and why? (Or which is a much better solution I don't see ;-) Thanks in advance, C.S.C. (* This is the interface I would like to have. *) module type MT = sig class type ct = object method get_c' : ct' method m : int end and ct' = object method get_c : ct method m' : int end class c : int -> ct class c' : int -> ct' end ;; module M : MT = struct (* This is the implementation: obj and obj' are the two public methods * I want to hide. *) class _c (obj : int) = object method obj = obj method get_c' = new _c' obj method m = (new _c' obj)#obj' end and _c' obj = object method obj' = obj method get_c = new _c obj method m' = (new _c obj)#obj end (* Again the interface... *) class type ct = object method get_c' : ct' method m : int end and ct' = object method get_c : ct method m' : int end (* The two proxy objects *) class c obj = let o = new _c obj in object method get_c' = (o#get_c' : _c' :> ct') method m = o#m end class c' obj = let o = new _c' obj in object method get_c = (o#get_c : _c :> ct) method m' = o#m' end end ;; -- ---------------------------------------------------------------- Real name: Claudio Sacerdoti Coen PhD Student in Computer Science at University of Bologna E-mail: sacerdot@cs.unibo.it http://caristudenti.cs.unibo.it/~sacerdot ---------------------------------------------------------------- ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr