[Swift-devel] typed keys

Ben Clifford benc at hawaga.org.uk
Sun Jul 24 05:42:02 CDT 2011


> > introduce runtime type errors: 5+"monkey" (for example) or inability
> > to add two numbers (5+5 = TYPE ERROR! because those 5s happen to be
> > Objects not numbers)
> 
> You would not be able to use these things in any other context than the
> places that accept the any type. Such as trace() and whatever else is
> there that fits, but not "+".

So should this work? O rather, how liberal does compile time type checking 
have to be to allow it to work at runtime?

int a[]; int b[]
populate(a); populate(b); // with number indices
for v,k in a {
 for u,l in b {
  o[k*1000 + l] = f(u,v)
 }
}

Its something that works at the moment. I don't think this style is used a 
huge amount but I think it has been done in the past. Constructing string 
indices by concatenating things is another example of the same, I think.

With a runtime top-type, the compile time checking needs to be quite 
loose, I think - here k and l are used numerically, but if you're keeping 
the discovery of the numericness 'till runtime, then you can't know at 
compile time.

Maybe that is an argument in favour of some compile time inference.

-- 



More information about the Swift-devel mailing list