dslomov / typed-objects-es7

ES7 typed objects spec draft
127 stars 7 forks source link

The array() constructor should permit an example as well as lengths #4

Open nikomatsakis opened 10 years ago

nikomatsakis commented 10 years ago

I think It should be possible to write all of the following:

T.array() // instantiates empty array of T (T[0])
T.array(W) // instantiates an array of length W
T.array([a, b, c]) // instantiates an array of length 1 with data from a, b, and c

I'm not sure about T.array(W, H). I originally wanted to support that, but I do not particularly want to support a multi-dimensional array example form. That seems to require that the full dimensions be specified, it cannot be (easily) inferred from the example itself, so I'd rather people write:

T.ArrayType(W, H)([[a, b, c], [d, e, f]])

Maybe it's nicer to just only have the one-dimensional versions of everything. So the previous example would become:

T.ArrayType(H).ArrayType(W)([[...], [...]])