From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA19947; Sat, 3 Aug 2002 19:52:05 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA19932 for ; Sat, 3 Aug 2002 19:52:04 +0200 (MET DST) Received: from lobus.fungible.com (adsl-64-161-114-6.dsl.snfc21.pacbell.net [64.161.114.6]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g73HlRf08252 for ; Sat, 3 Aug 2002 19:47:40 +0200 (MET DST) Received: by lobus.fungible.com (Postfix, from userid 1000) id C180B7F66; Sat, 3 Aug 2002 10:47:24 -0700 (PDT) Date: Sat, 3 Aug 2002 10:42:44 -0700 From-Tims-Fingers: true To: shoh@duonix.com Cc: caml-list@inria.fr In-reply-to: <002d01c23aae$b44a6490$fe00a8c0@hama> (shoh@duonix.com) Subject: Re: [Caml-list] How to implement "Singleton" design pattern? References: <002d01c23aae$b44a6490$fe00a8c0@hama> Message-Id: <20020803174724.C180B7F66@lobus.fungible.com> From: tim@fungible.com (Tim Freeman) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >(a) invisible class definition in a module Yes. Singleton.ml has: class type singleton = object method whatever: int end class singleton_impl: singleton = object method whatever: int = 7 end let theSingleton: singleton option ref = ref None let getInstance (): singleton = match !theSingleton with None -> let result = new singleton_impl in theSingleton := Some result; result | Some result -> result Singleton.mli has: class type singleton = object method whatever: int end val getInstance: unit -> singleton >(b) the class definition which can't be called with "new" (private class ?) I don't know how to do that except by hiding it with a signature as above. >(c) local class definition (in another class definition ?) I don't think you can nest class definitions. -- Tim Freeman tim@fungible.com GPG public key fingerprint ECDF 46F8 3B80 BB9E 575D 7180 76DF FE00 34B1 5C78 ------------------- 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