typed-objects-es7 icon indicating copy to clipboard operation
typed-objects-es7 copied to clipboard

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

Open nikomatsakis opened this issue 11 years ago • 0 comments

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)([[...], [...]])

nikomatsakis avatar Mar 14 '14 18:03 nikomatsakis