[Swift-devel] Explicit subscript types at declaration
Mihael Hategan
hategan at mcs.anl.gov
Thu Jun 30 13:57:02 CDT 2011
On Fri, 2011-07-01 at 00:14 +0530, Yadu Nand wrote:
> Hi,
>
>
> > 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.
More information about the Swift-devel
mailing list