[Swift-devel] typed keys

Yadu Nand yadudoc1729 at gmail.com
Sat Jul 23 12:37:12 CDT 2011


> There are a few solutions I can think of:
> 1. Have a universal type, which is what is used when saying array[].
> That would allow both array[0] = value, array["key"] = value, and array
> << value. Also allow auto-increment on array[string]. This will keep
> compatibility with existing scripts (i.e. allowing int keys when there
> is no explicit key type in the declaration). This would require us to be
> clear about when and how the universal/top type can be used.
Are you suggesting something like an object type ? But wouldn't that
reduce the strongly-typed 'ness of the language ?

> 2. Have an auto-increment key type and only allow << on those. I believe
> that Ben mentioned something like this.
Why do we need a separate type ? Or, are you saying the user would say
array[int]["auto-inc"] and we'd internally use strings ?

> 3. Require that arrays supporting << be array[string] and keep array[]
> as array[int].
This is probably the simplest way to go about it. I could perhaps add
some extra checks to ensure that the subscript has been declared as
string.

This is probably a language decision which I shouldn't influence
because I tend to lean towards ease of implementation :)

-- 
Thanks and Regards,
Yadu Nand B



More information about the Swift-devel mailing list