caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Didier Remy <Didier.Remy@inria.fr>
To: james woodyatt <jhw@wetware.com>
Cc: The Trade <caml-list@inria.fr>
Subject: Re: [Caml-list] functional objects
Date: Sat, 19 Oct 2002 22:48:23 +0200	[thread overview]
Message-ID: <20021019224823.A17599@morgon.inria.fr> (raw)
In-Reply-To: <5BF65502-E2FD-11D6-B29D-000393BA7EBA@wetware.com>; from jhw@wetware.com on Fri, Oct 18, 2002 at 05:54:45PM -0700

> Anyway, one of the things I find lacking is a way to call a subclass 
> constructor in the copy constructor.  In other words, I'd like to have 
> some way to do the following:
> 
> 	(* class type with only public methods exposed *)
> 	class type foo = object method f: unit end
> 
> 	(* class with private members *)
> 	class foo x : foo = object
> 	  val x: int = x
> 	  method f = ()
> 	end
> 
> 	(* derived functional subclass (notice method g) *)
> 	class bar y = object
> 	  inherit foo 0
> 	  val y: int = y
> 	  method g a b = {< foo a; y = b >}
> 	end
> 
> What I want is for a superclass class to be able to expose an interface 
> to subclasses for constructing copies with arguments.  Is this a bad 
> idea?  Has it already been considered and rejected?  Just curious.

Would the following code makes you happy?

        (* class type with only public methods exposed,
           plus a private overriding method foo *)
        class type foo_ = 
          object ('a) method f : unit method private foo : int -> 'a end;;

        (* class with private members *)
        class foo x : foo_ = object
          val x: int = x
          private method foo a = {< x = a >}
          method f = ()
        end;;

        (* derived functional subclass (notice method g) *)
        class bar y = object
          inherit foo 0
          val y: int = y
          method g a b = {< y = b >} # foo a 
        end;;

Didier Rémy
-------------------
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-10-20  7:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-19  0:54 james woodyatt
2002-10-19 20:48 ` Didier Remy [this message]
2002-10-21  4:10   ` james woodyatt
2002-10-21  6:55     ` Didier Remy
2002-10-21 18:40       ` james woodyatt
2002-10-22  8:42         ` Didier Remy

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=20021019224823.A17599@morgon.inria.fr \
    --to=didier.remy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=jhw@wetware.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).