Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] prevent more than one object
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nick Name <>
Subject: Re: [Caml-list] prevent more than one object
On Wed, 02 Jul 2003 18:14:23 +0200
Mirko Aigner <> wrote:

>  The problem is the class is still public and instances can be build,
>  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

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

  let x = new singleton

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


Ho dato al mio dolore la forma di parole abusate
che mi prometto di non pronunciare mai più

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: