[Swift-devel] Explicit subscript type declaration for arrays

Yadu Nand yadudoc1729 at gmail.com
Thu Jul 7 15:10:52 CDT 2011


> You could start with support for only primitive types as indices (i.e.
> Type.isPrimitive()).
Currently, this is what I'm doing. Though the logic I'm using requires
listing out the types listed under the hashmap types in  types.java.
I'll post behavior on cases where types defined earlier (besides the
primitives) are used as subscripts.

> In terms of the structs, these look like.. structs:
> type mystruct {
>  int a;
>  string b;
> }
>
> What's needed if they are to be used for array keys is an equality test,
> which can be straightforwardly done in the struct case by comparing
> field values recursively. Since non-primitive types cannot really be
> compared properly at this time, this would probably mean that
> non-primitive types should not be allowed in composite types that can be
> array keys.

Will it be any different if whenever we use a composite type we create
a string hashcode as the key ? Will this not eliminate the issue of
comparison ? I'm not sure if we can create a hashcode, and I bet the
subscript type issues are going to be weird with the declaration pointing
to a type and the actual type being a string.

Is the following the expected syntax in this case ?

type my_struct {
    int num ;
    string name;
}

int array [ int ] [ my_struct ];

-- 
Thanks and Regards,
Yadu Nand B



More information about the Swift-devel mailing list