<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/07/3b8654b28f0205244174f3bebd7b9f1d"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-07-20T01:31:26"
  subject="Re: [Caml-list] Protected methods"
  prev="2002/07/81fc8ddbc96bf9fd110437441913de3f"
  next="2002/07/ad6a52f05ed89cbcbc5e8d1d6b548581"
  prev-in-thread="2002/07/ad6a52f05ed89cbcbc5e8d1d6b548581"
  next-in-thread="2002/07/a8d866581e1a8f5a36577e0e1cde4f43"
  prev-thread="2002/07/647457434ab87dabf18062d5a922a07a"
  next-thread="2002/07/444e872df95c217576d95f578cc60764"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Protected methods">
<msg 
  url="2002/07/16bf0e05b121ad70d4407203ffcc2060"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-18T10:35:08"
  subject="[Caml-list] Protected methods">
<msg 
  url="2002/07/88d493b339b48ff3f330f1bdca3584fd"
  from="Gerd Stolpmann &lt;info@g...&gt;"
  author="Gerd Stolpmann"
  date="2002-07-18T11:01:34"
  subject="Re: [Caml-list] Protected methods">
<msg 
  url="2002/07/0bc4a82400e651216916e4f977a464bb"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-18T11:37:17"
  subject="Re: [Caml-list] Protected methods">
<msg 
  url="2002/07/97468669ddc77bef0c774de5284d4edc"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-07-19T08:50:13"
  subject="Re: [Caml-list] Protected methods">
<msg 
  url="2002/07/95b53058ae34958c36f4248bad4a51d8"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-19T09:53:56"
  subject="Re: [Caml-list] Protected methods">
<msg 
  url="2002/07/81fc8ddbc96bf9fd110437441913de3f"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-07-20T00:46:55"
  subject="Re: [Caml-list] Protected methods">
<msg 
  url="2002/07/ad6a52f05ed89cbcbc5e8d1d6b548581"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-20T07:34:16"
  subject="Re: [Caml-list] Protected methods">
</msg>
</msg>
<msg 
  url="2002/07/3b8654b28f0205244174f3bebd7b9f1d"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-07-20T01:31:26"
  subject="Re: [Caml-list] Protected methods">
<msg 
  url="2002/07/a8d866581e1a8f5a36577e0e1cde4f43"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-20T07:41:03"
  subject="Re: [Caml-list] Protected methods">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2002/07/82e9eedb518a1b06dbd968154ac21e67"
  from="Dmitry Bely &lt;dbely@m...&gt;"
  author="Dmitry Bely"
  date="2002-07-20T22:55:22"
  subject="Re: [Caml-list] Protected methods">
<msg 
  url="2002/07/43384b3c4e0ffaa4c68217d2e6be8043"
  from="Brian Smith &lt;brian-l-smith@u...&gt;"
  author="Brian Smith"
  date="2002-07-20T23:08:12"
  subject="Re: [Caml-list] Protected methods">
<msg 
  url="2002/07/c52712390dd950b3b1df7a8c40fd0ec8"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-07-22T03:37:42"
  subject="OCaml&apos;s OO design Re: [Caml-list] Protected methods">
<msg 
  url="2002/07/331705def71aab66cd579f8d5b34e217"
  from="John Prevost &lt;j.prevost@c...&gt;"
  author="John Prevost"
  date="2002-07-22T04:13:24"
  subject="Re: OCaml&apos;s OO design Re: [Caml-list] Protected methods">
</msg>
</msg>
</msg>
<msg 
  url="2002/07/4d88ea7bc8989476801d171755a1653d"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-20T23:53:19"
  subject="Re: [Caml-list] Protected methods">
<msg 
  url="2002/07/ceef67ffac4fa576044134564c761207"
  from="Dmitry Bely &lt;dbely@m...&gt;"
  author="Dmitry Bely"
  date="2002-07-21T07:55:23"
  subject="Re: [Caml-list] Protected methods">
<msg 
  url="2002/07/b6696076b1bd316d89f212c2d6849e48"
  from="Alessandro Baretta &lt;alex@b...&gt;"
  author="Alessandro Baretta"
  date="2002-07-21T13:07:07"
  subject="Re: [Caml-list] Protected methods">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
From: Alessandro Baretta &lt;alex@baretta.com&gt;

&gt; How about the following pseudocode? Is it sensible/viable?
&gt; 
&gt; let module M : sig
&gt;    class type public = object &lt;public_methods&gt; end
&gt;    val make_public : unit -&gt; public
&gt; end = struct
&gt;    class type public = object &lt;public_methods&gt; end
&gt;    class protectd =
&gt;      object (self : #public)
&gt;      &lt;public_methods&gt;
&gt;      &lt;protected_methods&gt;
&gt;    end
&gt;    let make_public () -&gt; (new protected :&gt; public)
&gt; 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.

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

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

The point is that now you can access the protected methods while
your code appears in the same module, through the full method (which
just returns self, but with its protected methods accessible), but not
from outside the module (hidden is abstract).

Note also how I exported protected as virtual: this way you cannot
create objects from it, but you can still use it through inheritance.
If you don't need to inherit, you don't have to export it though, and
then you don't have to distinguish protected and hidden either.

Here is a concrete instance of that, to verify the type checking:

module M : sig
  type hidden
  class type public = object method pub : int  method full : hidden end
  val make_public : unit -&gt; public
  val call_prot : public -&gt; int
  class virtual protected : object ('a)
    method pub : int
    method prot : int
    method full : 'a
  end
end = struct
  class protected = object (self)
    method prot = 1
    method pub = self#prot
    method full = self
  end
  type hidden = protected
  class type public = object method pub : int  method full : hidden end
  let make_public () = (new protected : protected :&gt; public)
  let call_prot (o : public) = o#full#prot
end

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

</contents>

</message>

