caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: caml-list <caml-list@inria.fr>
Subject: [Caml-list] Delegation
Date: 31 Mar 2004 19:18:15 +1000	[thread overview]
Message-ID: <1080724695.13269.156.camel@pelican.wigram> (raw)

With the module system, I can write a functor requiring
a function called 'foo' with some signature.

When I instantiate the functor I can construct
a module argument 'on the fly' to rename any function
I'm passing like:

	let g () = ...
	module M = F (struct val f = g end)

So that the names used in the functor are arbitrary
and can bind to any entity with suitable renaming.
[At least I gather this is the intent]

Is there a way to do this with classes?

A typical problem is: our class actually has
the correct methods, but they're named wrong.
A extension is: we have the right method,
except the argument order is different.
An extension of that is: we don't have exactly
the right methods, but we can easily construct them.

All these cases can easily be solved with a proxy object
that delegates most of the method calls, perhaps with
some argument reordering or minor fiddling.

But is there a convenient way to construct such objects
anonymously at the point needed? After all class types
are signature based ..

Hmmm.. can I write:

	(fun o -> object method f: init = o#g end)#f

given o has a method g of suitable type but wrong name?

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
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:[~2004-03-31  9:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-31  9:18 skaller [this message]
2004-03-31  3:57 ` Issac Trotts
2004-03-31 13:16   ` skaller

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=1080724695.13269.156.camel@pelican.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    /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).