caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] Delegation
  2004-03-31  9:18 [Caml-list] Delegation skaller
@ 2004-03-31  3:57 ` Issac Trotts
  2004-03-31 13:16   ` skaller
  0 siblings, 1 reply; 3+ messages in thread
From: Issac Trotts @ 2004-03-31  3:57 UTC (permalink / raw)
  To: skaller; +Cc: caml-list

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

In the CVS version of OCaml, you can make objects of anonymous
class.  Have a look at

    http://caml.inria.fr/archives/200402/msg00164.html

--
Issac Trotts

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Caml-list] Delegation
@ 2004-03-31  9:18 skaller
  2004-03-31  3:57 ` Issac Trotts
  0 siblings, 1 reply; 3+ messages in thread
From: skaller @ 2004-03-31  9:18 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Delegation
  2004-03-31  3:57 ` Issac Trotts
@ 2004-03-31 13:16   ` skaller
  0 siblings, 0 replies; 3+ messages in thread
From: skaller @ 2004-03-31 13:16 UTC (permalink / raw)
  To: Issac Trotts; +Cc: skaller, caml-list

On Wed, 2004-03-31 at 13:57, Issac Trotts wrote:
> > 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?
> 
> In the CVS version of OCaml, you can make objects of anonymous
> class.  Have a look at
> 
>     http://caml.inria.fr/archives/200402/msg00164.html

Oooo... thank you for that link: looks perfect!

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-03-31 13:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-31  9:18 [Caml-list] Delegation skaller
2004-03-31  3:57 ` Issac Trotts
2004-03-31 13:16   ` skaller

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).