Self type

Nicolas Cannasse ncannasse at motion-twin.com
Tue Aug 14 12:46:21 PDT 2007


Brendan Eich a écrit :
> On Aug 14, 2007, at 10:10 AM, liorean wrote:
> 
>>> Peter Hall wrote:
>>>> type B = {b:Self};
>> On 14/08/07, Cormac Flanagan <cormac at soe.ucsc.edu> wrote:
>>> Yes, I think this should be fine.
>> I'm all for allowing recursive structural types e.g. for use as binary
>> trees or linked lists.
>>
>>     type BinTree = {sin:Self, dx:Self, value:*};
> 
> We've decided *not* to specify recursive structural types in general.  
> The subtype relation is O(exp(n)) for the simpler algorithm [1], and O 
> (n^2) for a fairly complex successor algorithm [1]. In the interest  
> of simplicity and to minimize costs to small-device implementations,  
> we are leaving out recursive structural types of ES4. They could be  
> added later; for now, if you need trees and the like, use nominal types.

That's too bad.

Have you not considered having a two-level type spec ? One for 
compile-time and one for runtime ? If I'm not wrong, Java did that with 
generics.

But anyway, haXe allows :

typedef BinTree<T> = {
    var value : T;
    var left : BinTree<T>;
    var right : BinTree<T>;
}

Which can be generated as the former (less typed) BinTree definition 
while still getting proper compile-time typechecking.

The only problem so far is that it seems there is no structural types 
support in AVM2/Tamarin yet, or did I miss it ?

Best,
Nicolas




More information about the Es4-discuss mailing list