From: james woodyatt <jhw@wetware.com>
To: The Caml Trade <caml-list@inria.fr>
Subject: wish for something like 'restricted' methods
Date: Tue, 22 Mar 2005 15:34:44 -0800 [thread overview]
Message-ID: <1b4c73f40a9fe87d2bcf34c14afa1e74@wetware.com> (raw)
In-Reply-To: <6b8a91420503221156e994d7c@mail.gmail.com>
On Mar 22, 2005, at 11:56 AM, Remi Vanicat wrote:
>
> In ocaml, you can only call a private method on self. super#forward
> is not self, so you cannot call the color_forward method on it. Then
> as a private method can be made public latter, ocaml make the method
> public to make the code correct, and give you this warning.
This discussion reminds me of a related issue that has always made me
wonder if the language couldn't be improved a little.
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.
An example:
class type ['q] p =
object
constraint 'q = #q
method restricted f: 'q -> unit
end
and q =
object
val p: #q #p
method g: unit
end
In the class type definition above, I want objects of class type q to
be able to define a method g which delegates to the method f defined in
class type 'q p, but I don't want the delegate to be visible outside
methods in objects of type (or subtypes) of 'q p and q (which is
currently the case).
I would expect that, with inheritance, restricted methods would be
implicitly inherited, private methods could be explicitly promoted to
restricted methods, and restricted methods could be explicitly promoted
to public methods. I would also expect that restricted methods could
also be virtual methods.
I can see how restricted methods would have to appear in object types,
and they would need to be distinguished from public methods
appropriately, i.e. (< restricted 'p 'q. f: 'q. (#q as 'q) -> unit; ..
> as 'p) would describe an object with a method f restricted to methods
in objects of a limited set of types, listed as 'p and 'q in the type.
The "restricted 'p 'q." clause would separate the public methods from
the restricted methods.
It would be especially nice if class type constraints could be used to
hide a restricted method or explicitly constrain it to be just a
private method. That would allow class types in module signatures to
present restricted methods as private methods outside the module
structure when the class definitions inside the module structure
defines the methods as restricted.
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.
I suppose I might consider (whenever I get the time and inclination)
the problem of writing a CamlP4 extension to do something like this,
but my intuition tells me it would be better if it was handled by the
compiler itself.
Note: I recognize that this language feature could not be used to solve
the problem that M. Herbert is raising in the referenced thread.
--
james woodyatt <jhw@wetware.com>
next prev parent reply other threads:[~2005-03-22 23:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-22 19:18 extending a functional updater implicitly publicizes sub-updater method? Marc Herbert
2005-03-22 19:56 ` [Caml-list] " Remi Vanicat
2005-03-22 23:34 ` james woodyatt [this message]
2005-03-23 5:03 ` [Caml-list] wish for something like 'restricted' methods Jacques Garrigue
2005-03-23 8:22 ` james woodyatt
2005-03-30 13:16 ` private methods restricted to self? Marc Herbert
2005-03-31 2:30 ` [Caml-list] " Jacques Garrigue
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1b4c73f40a9fe87d2bcf34c14afa1e74@wetware.com \
--to=jhw@wetware.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox