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 CAA14155; Wed, 13 Oct 2004 02:49:19 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 CAA14140 for ; Wed, 13 Oct 2004 02:49:18 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i9D0nFcn013052 for ; Wed, 13 Oct 2004 02:49:17 +0200 Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2-20030924/3.7W) with ESMTP id JAA14161; Wed, 13 Oct 2004 09:49:09 +0900 (JST) Date: Wed, 13 Oct 2004 09:49:03 +0900 (JST) Message-Id: <20041013.094903.08315159.garrigue@kurims.kyoto-u.ac.jp> To: edgin@slingshot.co.nz Cc: caml-list@inria.fr Subject: Re: [Caml-list] Narrowing class's public interface From: Jacques Garrigue In-Reply-To: <200410131116.12485.edgin@slingshot.co.nz> References: <200410131116.12485.edgin@slingshot.co.nz> X-Mailer: Mew version 4.0.64 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 416C7B8B.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 narrowing:01 class's:01 jacques:01 soundness:01 java's:01 java's:01 subtyping:01 wwwfun:01 jacques:01 htmlman:01 ocaml:01 ocaml:01 garrigue:01 garrigue:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Tony Edgin > What is the reasoning behind Ocaml not allowing the public methods > of a class to be hidden? This is just a type soundness problem: as an ocaml object type only describes the interface of an object, you have no way to make sure that an object had originally a specific method (with the right type) once you have hidden it. Of course we could add some kind of declaration like method hidden m : type and allow a subclass to convert a public method into such an "hidden" one, but I'm quite sure this is not what you are asking for? (Note that such an addition would be rather heavy, as "hidden" method must appear in object types too, i.e. < hidden m : type; ... >) > 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. This problem has been thought of :-) Look at the user's manual, section 3.17, for how to define "friend" methods, i.e. methods accessible only from code in the same module. Note that since ocaml modules are hierarchical, this actually allows you more precision than Java's packages. http://wwwfun.kurims.kyoto-u.ac.jp/soft/ocaml/htmlman/manual005.html#ss:friends Jacques Garrigue ------------------- 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