Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Delegation
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: [Caml-list] Delegation
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