[Swift-devel] Explicit subscript types at declaration

Yadu Nand yadudoc1729 at gmail.com
Thu Jun 30 14:04:57 CDT 2011


>> > This involves saying ,
>> > int assoc_array[string][int][ ]
>> > (where empty brackets implicity mean int )
>>
>> This is hard. It would mean a lot of effort in terms of code from what
>> I understand.
>
> Yes, it's not trivial. But what fun would it be if it was?
>
>>  Further more, It also means less flexibility for the user
>> in terms of the type of subscript.
>
> Maybe.
>
>>
>> Is it wrong for the user to say,
>> array[5] = 10;
>> array["key"] = 25;
>>
>> If this is dealt with at the foreach level, by doing type inference of the
>> index, I think this would be easier. This would mean we would need
>> to change the type of the index in the template for foreach to say,
>> _UNDEF_
>>
>
> Well, swift doesn't have a universal type (i.e. Object, (void *)), so a
> mix between int and string doesn't really have a proper type. It follows
> that one should either have array[5] or array["key"] but not both for
> the same array.

Okay. Then I'll have it done so that, empty brackets are still implicitly
int.

-- 
Thanks and Regards,
Yadu Nand B



More information about the Swift-devel mailing list