Non-generic traps for non-generic objects (was: Overriding Map/etc with get/set hooks?)

Andreas Rossberg rossberg at google.com
Fri May 24 10:11:58 PDT 2013


On 24 May 2013 18:55, Tab Atkins Jr. <jackalmage at gmail.com> wrote:
> I simply don't understand why Javascript's Map apparently makes this
> impossible, forcing all Maps to be any->any, and offering only hacks
> (admittedly clever ones) that partially work if you want a restricted
> type.

I haven't really followed this thread, but could it be that you are
confusing polymorphic instantiation with subtyping here? A Map(String,
String) is an instance of a polymorphic Map(A, B), but it is not a
subtype of Map(Any, Any), because a map is contravariant in its key
type. That's why the subclassing you have in mind does not really make
sense from a subtyping perspective. If you want to restrict it, then
you'd have to do so by wrapping, not by inheritance.

/Andreas


More information about the es-discuss mailing list