Self type

Brendan Eich brendan at mozilla.org
Tue Aug 14 10:46:15 PDT 2007


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.

Dave Herman's analysis is on the wiki, but for some reason I'm  
getting an error trying to access the relevant page [3].

Self-references may be good enough for common "recursive" cases  
(iterator::get, clone, equals, etc.).

/be

[1] http://research.microsoft.com/Users/luca/Papers/SRT.pdf
[2] http://www.cs.ucla.edu/~palsberg/paper/mscs95-kps.pdf
[3] https://wiki.ecmascript.org/ECMA/wiki/doku.php? 
id=discussion:classes_as_structural_types_with_branding




More information about the Es4-discuss mailing list