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: Mirko Aigner <Mirko.Aigner@a...>
Subject: [Caml-list] prevent more than one object
Hi !

I'm looking for a way to prevent that from a class more than one object 
is builded. Therefor I wrote this little files

class singleton x =
     val mutable data : int = x;
     method get_data = data;
     method set_data newdata = data <- newdata;

let instance = new singleton 0

let get_instance = instance

class singleton :
   int ->
     method get_data : int
     method set_data : int -> unit

val get_instance : singleton

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

thx for helping
Mirko Aigner

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