Version française
Home     About     Download     Resources     Contact us    
Browse thread
extending a functional updater implicitly publicizes sub-updater method?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] wish for something like 'restricted' methods
From: james woodyatt <jhw@wetware.com>

> I'd like to be able to define a method that isn't public, but also 
> isn't private.  I don't know what to call this method qualification.  
> For the purposes of this discussion *only*, I'll pick a proposed word 
> to reserve: restricted.
> 
> A "restricted" method would be one that may only be invoked within the 
> methods of objects constrained to the type of any classtype-def in 
> their classtype-definition.

Reading the remainder of your mail, I couldn't understand your notion
of restricted method.
Maybe it would be better if you give an exemple of situation where you
need this new expressiveness, rather than explicitely define a new
notion, as there may be several solutions to your problem.

> Have ideas along these lines been considered or even researched?  I 
> realize that there are ways to get along without a feature like this, 
> and they're not that bad all things considered.  (Example: use public 
> methods with abstract types in the module signature, and delegate 
> through them to private methods with concrete types.)  This 
> "restricted" method type would just be a convenient way of allowing the 
> programmer to express this intent within the language itself.

Jerome Vouillon (the original implementor of the ocaml object system)
wrote a paper about using views to allow arbitrary hiding of methods.

 Combining subsumption and binary methods: An object calculus with views
 In Proceedings of the 28th ACM Conference on Principles of Programming
 Languages, pages 290\u2013303, 2001

This may be related to what you want. However there is no plan to
include views in ocaml.

On the other hand, I have just extended the ocaml type system to allow
the use of private structural types, i.e. abstract types where you
still allow access to some methods.
Then you can write something like this:

module M : sig
  type p = private < m: int; .. >
  type q = private < g: int; .. >
  val new_p : unit -> p
  val new_q : p -> q
end = struct
  class p = object
    method m = 3
    method f (q : q) = q#h
  end
  and q (x : p) = object (self)
    method g = x#f (self :> q)
    method h = 7
  end
  let new_p () = new p
  let new_q = new q
end

where f and h are "friend" methods.

Jacques Garrigue