[Swift-devel] typecheck foo[*].bar

Ben Clifford benc at hawaga.org.uk
Tue Feb 10 07:12:40 CST 2009


I noticed today that expressions like this don't get typechecked properly, 
so in 0.8, you can't use [*].member expressions. Bleugh.

As I want to use such expressions (or equivalent), I guess I have to fix 
that soonish.

I think the approach I am favouring language-wise is that [*] becomes a 
no-op/identity operator, and . with an array of structs on the left 
returns an array of the appropriate member fields.

Thus   a[*] == a   for all arrays a

       a[*].foo == a.foo == (in haskelly pseudocode) (map \(x->x.foo) a)

I think from an implementation point of view, that can cause some trouble 
though. DSHandles expect to have only one parent. Writing an expression 
a[*].foo causes each element to then have two potential parents:

     i.        array of structs  -> contained structure -> foo
     ii.       array of foos -> foo

Although something like this must be happening at the moment anyway with 
the [*].foo syntax, so it might not turn out to be a big deal.

-- 




More information about the Swift-devel mailing list