Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Protected methods
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alessandro Baretta <alex@b...>
Subject: Re: [Caml-list] Protected methods


Jacques Garrigue wrote:
> From: Alessandro Baretta <alex@baretta.com>
> 
>>How about the following pseudocode? Is it sensible/viable?
>>
>>let module M : sig
>>   class type public = object <public_methods> end
>>   val make_public : unit -> public
>>end = struct
>>   class type public = object <public_methods> end
>>   class protectd =
>>     object (self : #public)
>>     <public_methods>
>>     <protected_methods>
>>   end
>>   let make_public () -> (new protected :> public)
>>end
> 
> 
> Actually, after a more thorough look at your code, I'm not sure of
> what you're trying to achieve with it.  Applied directly, it seems
> that it would give you no more than private methods: you can not use
> them outside of the class.

Allowing different instances of a class to invoke protected 
methods on each other, without these methods being exported 
to the general public.

> And I've found a better idiom, that should do about anything you want.

Success! :-)

> module M : sig
>   type hidden
>   class type public = object < public methods >  method full : hidden end
>   val make_public : unit -> public
>   class virtual protected : object ('a)
>     < public methods >
>     < protected methods >
>     method full : 'a
>   end
> end = struct
>   class protected = object (self)
>     < public methods >
>     < protected methods >
>     method full = self
>   end
>   type hidden = protected
>   class type public = object < public methods >  method full : hidden end
>   let make_public () = (new protected : protected :> public)
> end

I publicly bow to another Jedi camler. May inheritance and 
subtyping be with you.

Alex

-------------------
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