On Wed, 2007-09-19 at 16:45 +1000, skaller wrote:
> Anyhow .. this CAN be done.
And now has been:
/////////////////////////////////////
#import <flx.flxh>
var x = struct {a=1; b=2; };
println q"a=$(x.a), b=$(x.b)";
var y = (a=3, b=4);
println q"a=$(y.a), b=$(y.b)";
struct X { aa:int; bb:int; };
val k = X (1,2);
println q"aa=$(k.aa), bb=$(k.bb)";
val j = X (bb=11,aa=22);
println q"aa=$(j.aa), bb=$(j.bb)";
val r = (bb=88,aa=99);
val q = X r;
println q"aa=$(q.aa), bb=$(q.bb)";
///////////////////////////////////////////
I have NOT checked if this works right with
polymorphic structs. NOTE the last case: the record
doesn't have to be given literally!
BTW: BUG report:
struct X { int a; int b; };
doesn't work! It should... (C syntax for component declarators .. )
Now .. whilst coding this I am thinking on this one:
fun f(a:int, b:int) ..
fun f(x:int, y:int)
f(x=1, y=2) //calls the second b
Basically, the idea is a function can take either a tuple or
record argument, even if the argument is specified as above
(rather than as a record type).
Related to this .. if the function takes a struct X argument,
it can also accept a record, if and only if
X r
is correct. For example:
fun f(x:X)..
f (a=1,y=2)
you could even argue
f (1,2)
should work. Note these cases DEFEAT strict nominal typing
so it isn't clear they should be allowed, especially the
last on f (1,2). The f (a=1,y=2) is also not strict, however
it is stricter because at least the components match.
So bottom line, the case:
f(x=1, y=2) //calls the second b
may be implementable. I think this would be done much like the
implementation for struct init, only now we have a SET of functions.
This has to be done in overload resolution (which is the scariest
or second scariest routine in Felix compiler):
If a candidate fails to unify (try that first in case the function
was defined to accept a record), and the argument is a record,
then convert the argument to a tuple by name correlation with
the function parameter names, and try to match that.
This is how the struct init works. However in this case,
overload resolution returns a function, but we have to
make sure the generated application (or call) is applied
to the permuted tuple, eg:
fun f(x:int, y:int)
f (y=2,x=1) --->> f (1,2)
and not the original argument.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language