Browse thread
[Caml-list] Protected methods
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Gerd Stolpmann <info@g...> |
| Subject: | Re: [Caml-list] Protected methods |
Alessandro Baretta wrote: > I'm trying to get the semantics of protected methods of C++. I have a > class with a method that is not meaningful for the outside world, but > different instances of this class should be able to invoke this method > on one another. > > I need something like the following pseudocode: > > class a = > object > method protected m = ... > method m2 (obj:a) = a # m > end > > I understand this can be obtained by creating a container module for > class a and restricting the type of a through the module signature. I > read the manual but was unable to figure out the syntax to do this. > Would anyone be so kind as to lend a hand? No, you cannot restrict the type of classes by signatures. The only way I know to protect a method is to define an opaque type that is hidden by the signature, e.g. sample.ml: type protector = unit class a = object method m () = ... ... end sample.mli: type protector class a : object method m : protector -> XXX ... end You cannot call m from other modules because you cannot create values for the type "protector". Gerd -- ------------------------------------------------------------ Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de ------------------------------------------------------------ ------------------- 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