[Swift-devel] Explicit subscript type declaration for arrays
Mihael Hategan
hategan at mcs.anl.gov
Thu Jul 7 15:42:45 CDT 2011
On Fri, 2011-07-08 at 01:40 +0530, Yadu Nand wrote:
> > 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 ?
If you can guarantee that for every two different structs the hash codes
are different then it's only a matter of which implementation is
simpler/more clear.
> Will this not eliminate the issue of
> comparison ?
No. It is a solution to the issue of comparison. Though I suspect it's
not a very good one.
> 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 ];
>
Yes.
More information about the Swift-devel
mailing list