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 AAA10367; Wed, 13 Oct 2004 00:16:55 +0200 (MET DST) 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 AAA10295 for ; Wed, 13 Oct 2004 00:16:54 +0200 (MET DST) Received: from mxsrv2.tranzpeer.net (mxsrv2.tranzpeer.net [202.180.66.215]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i9CMGoIH009752 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Wed, 13 Oct 2004 00:16:53 +0200 Received: from [202.180.104.210] (helo=p210.cpich1-n1.callplus.net.nz) by mxsrv2.tranzpeer.net with ASMTP (Exim 4.34) id 1CHUwo-0000el-J8 for caml-list@inria.fr; Wed, 13 Oct 2004 11:16:48 +1300 From: Tony Edgin Reply-To: edgin@slingshot.co.nz Organization: CARP To: caml-list@inria.fr Subject: [Caml-list] Narrowing class's public interface Date: Wed, 13 Oct 2004 11:16:12 +1300 User-Agent: KMail/1.5.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200410131116.12485.edgin@slingshot.co.nz> X-Miltered: at concorde with ID 416C57D2.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; narrowing:01 class's:01 java's:01 java's:01 subtyping:01 struct:01 gaussian:01 elided:01 gaussian:01 ocaml:01 reasoning:02 float:02 float:02 modules:02 modules:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk What is the reasoning behind Ocaml not allowing the public methods of a class to be hidden? Some times its nice for a class to have "global" public methods (Java's public methods) as well as public methods local to its module (Java's unprefixed methods). This allows for progressive encapsulation, where more distance modules no very little about a class, while the more local modules know more about the class. Inheritance could be used to approximate this, but sometimes subtyping makes more sense. I apologize for my lack of clarity. For those who couldn't understand my question, here's an example. module RandomVariables = struct class type rv_type = object method instance : float method scale_by : float -> rv_type method add : rv_type -> rv_type end class gaussian _stdev _mean = object method stdev = _stdev method mean = _mean method instance = (* elided *) (** Returns a draw from the corresponding distribution. *) method scale_by a = new gaussian ((abs_float a)*._stdev) (a*._mean) method add (other : guassian) = let sigma = sqrt (_stdev**2. +. other#stdev**2.) and mu = _mean +. other#mean in new gaussian sigma mu end (* Truncated *) end (* Bad code which I would like to use *) class gaussian_rv = (RandomVariables.gaussian float -> float -> RandomVariables.rv_type) ;; cheers. -- Tony Edgin CARP ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners