need some clarification on compile-time type vs. run-time type

Brendan Eich brendan at mozilla.org
Sun Nov 11 22:35:46 PST 2007


On Nov 11, 2007, at 4:26 PM, Brendan Eich wrote:

> Part of the thinking in
> resolving #103 in favor of type expression on right of 'is' was to
> future-proof against a world where type and value expressions are
> combined somehow. I don't believe that world will come to pass,
> though. If it should, sooner is better. Restricting 'is' as #103-as-
> resolved did isn't making anyone too happy right now :-/.

Of course, Lars cut the Gordian knot in email just a bit later today:

   type T
   var v

   x is T               // if T is type then the compiler knows that,
                        // otherwise next case applies
   x is v               // reflect::typeOf(x).isSubtypeOf(v)
                        // fails if v not a Type object
   x is { ... }         // interpret as record type
   x is [ ... ]         // interpret as array type
   x is ( ... )         // interpret as union type
   x is function ...    // interpret as function type
   x is null            // interpret as null type
   x is undefined       // interpret as undefined type
   x is like T          // T must be a type expression anyhow

This allows arbitrary value expressions on the right of 'is', just so  
long as they don't look like type expressions in their leftmost  
token. Everyone wins. Yay?

/be



More information about the Es4-discuss mailing list