<?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="2003/07/1289d7b595f1d629c162939d33309862"
  from="Nick Name &lt;nick.name@i...&gt;"
  author="Nick Name"
  date="2003-07-02T16:42:04"
  subject="Re: [Caml-list] prevent more than one object"
  prev="2003/07/49d3704bd9b76044d06a619f87144574"
  next="2003/07/9d5c44985ef4846fa1879e4f91dc551f"
  prev-in-thread="2003/07/49d3704bd9b76044d06a619f87144574"
  next-in-thread="2003/07/e6b497b6561e6b659094f56674cbd2d4"
  prev-thread="2003/07/d3684049ef97610c271443c5f8c1c003"
  next-thread="2003/07/9d5c44985ef4846fa1879e4f91dc551f"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] prevent more than one object">
<msg 
  url="2003/07/49d3704bd9b76044d06a619f87144574"
  from="Mirko Aigner &lt;Mirko.Aigner@a...&gt;"
  author="Mirko Aigner"
  date="2003-07-02T16:14:24"
  subject="[Caml-list] prevent more than one object">
<msg 
  url="2003/07/1289d7b595f1d629c162939d33309862"
  from="Nick Name &lt;nick.name@i...&gt;"
  author="Nick Name"
  date="2003-07-02T16:42:04"
  subject="Re: [Caml-list] prevent more than one object">
</msg>
<msg 
  url="2003/07/e6b497b6561e6b659094f56674cbd2d4"
  from="John Max Skaller &lt;skaller@o...&gt;"
  author="John Max Skaller"
  date="2003-07-03T11:20:34"
  subject="Re: [Caml-list] prevent more than one object">
<msg 
  url="2003/07/1a00e490e8337df3f522867c8a55be6e"
  from="Mirko Aigner &lt;Mirko.Aigner@a...&gt;"
  author="Mirko Aigner"
  date="2003-07-03T11:36:21"
  subject="Re: [Caml-list] prevent more than one object">
</msg>
</msg>
</msg>
</thread>

<contents>
On Wed, 02 Jul 2003 18:14:23 +0200
Mirko Aigner &lt;Mirko.Aigner@alcatel.de&gt; wrote:

&gt; 
&gt;  The problem is the class is still public and instances can be build,
&gt;  any way to prevent this ?!

I would make the class private in the module and supply only access
functions; if you need it to be a class you should expose only the class
type, but there is Oo.copy so your value will never be granted unique.

Try this

module M : sig
  class type singleton = object
    method f : int
  end

  val x : singleton
end = 
struct
  class singleton = object
    method f = 0
  end

  let x = new singleton
end

You can't create a new singleton with "new" but still can do that with
Oo.copy M.x. It is better to completely hide the type if you can, as in

module M : sig
  type singleton

  val x : singleton
end = struct ...

Vincenzo

-- 
Ho dato al mio dolore la forma di parole abusate
che mi prometto di non pronunciare mai pił
[CSI]

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

