On 20/05/2012, at 7:05 PM, john skaller wrote:

> So here's object lambdas:
> 
> //////////
> val x = (a=1, b=2, c="m");
> val y = (c=9.9, s="Hello");
> 
> typedef X = (a:int, b:int, c:string);
> typedef Y = (c:double, s:string);
> typedef XYZ = extend X, Y with (k:string) end;
> 
> var xyz:XYZ = extend x,y with (k="world") end;
> 
> println$ xyz.a, xyz.b, xyz.c, xyz.s, xyz.k;
> println$ "Felix Rocks";
> 
> var a = object (x:int) = { omethod fun getx()=>x; };
> println$ (a 1).getx();
> var b = a 2;
> println$ b.getx();
> 
> var d = (object () = { omethod fun getit() => "it"; })();
> println$ d.getit();
> ////////////
> 

And I missed the fun part:

var xt = extend x,y, (a 1) with d end;
println$ xt.getit();

var xt2 = extend x,y, (a 1) with (object () = { omethod fun getit() => "it2"; 
}) () end;
println$ xt2.getit();


var objk42 = extend x,y, (a 1) with (object (var k:int) = { omethod fun getk() 
=> k; }) 42 end;
println$ objk42.getk();

Note that we're synthesising new objects. The "object" construction is NOT an 
object,
its an object FACTORY (i.e. a function returning an object .. which is just a 
record).

It's the same as a Java (or C++) class: you have to call the "constructor" on 
arguments
to get an actual object.

Is this what we really want? 

Certainly, the above is useful. But really, I think we wanted to merge together
the object factories, not objects, to get a new factory.

In other words we want to merge

        T1 -> R1
        T2 -> R2
        ...
        Tn -> Rn

into

        T1 * T2 * ... * Tn -> R

where R is the the merger of the record types R1  to Rn.

Alternatively, instead of T1 * .. * Tn we might want

        T1 * .. Tn-1 * pn1 * pn2 ....

where pn1, pn2 .. are the individual components of the tuple argument Tn

or perhaps we want

        T

where T is the merge of the tuples T1 .. Tn (i.e. a tuple with all the 
individual arguments).

In C++, your constructor reads:

        T(p1, p2, .. pn) : T1(...), T2(...) ... v1(..), v2 (.. ) { .. }

where the initialisers for the bases T1 to Tn-1 are calculated from constants
and the parameters p1 .. pn, ditto for member variables v1 .. vm.

Now of course, with the extend expression you can just do:

        fun f(...) => extend T1(...), T2(...), ... Tn-1(...) with (object ... ) 
(...) end;

so it's not clear if a syntax

        object Tn(...) extends T1(..), T2(...), ... = { omethod ... };

is worthwhile. Hmmm. Perhaps I should try. That seems the right form.
each of T1(...) etc is actually an object, except the arguments are parameters
of Tn (as in C++). However if you note the value extension syntax again:

var objk42 = extend x,y, (a 1) with (object (var k:int) = { omethod fun getk() 
=> k; }) 42 end;

it's not so easy to see how this will work (the parameter here is k, and is 
only available
to the derived object not the bases). Hmmm.. so we need instead the model:

        fun X (params) = {  return extend ... object ... end arg; }

Ah yes. That's nice. Trivialish in the parser!




--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to