caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: tim@fungible.com (Tim Freeman)
To: shoh@duonix.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] How to implement  "Singleton" design pattern?
Date: Sat,  3 Aug 2002 10:42:44 -0700	[thread overview]
Message-ID: <20020803174724.C180B7F66@lobus.fungible.com> (raw)
In-Reply-To: <002d01c23aae$b44a6490$fe00a8c0@hama> (shoh@duonix.com)

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


  reply	other threads:[~2002-08-03 17:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-03  5:29 SooHyoung Oh
2002-08-03 17:42 ` Tim Freeman [this message]
2002-08-05  9:28 ` Hendrik Tews
2002-08-05 17:48 Gurr, David (MED, self)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020803174724.C180B7F66@lobus.fungible.com \
    --to=tim@fungible.com \
    --cc=caml-list@inria.fr \
    --cc=shoh@duonix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).