Ticket #120 (new defect)

Opened 2 years ago

Last modified 7 months ago

(Resolved) Should array structural type syntax require explicit repetition

Reported by: brendan Assigned to: lth
Type: defect Priority: trivial
Milestone: M2 Component: Spec
Version: 4 Keywords:
Cc: lth, dherman, cormac, graydon, jeff, jorendorff

Description

We have today, from spec:type system,

type EmptyArray = [];
type AnyElemArray = [*];
type ZeroOrMoreInts = [int];
type OneOrMoreInts = [int, int];

The last element type repeats until index 232-2. And the last element is optional.

Note also that in the current proposal, the first two types are equivalent (and the first is misnamed).

I think it would be better if repetition (including zero times) were explicit:

type EmptyArray = [];
type AnyElemArray = [*];
type ZeroOrMoreInts = [int...];
type OneOrMoreInts = [int, int...];

where I'm using ... for Kleene * without actually proposing it as the concrete syntax. Whatever the syntax, the point is that array structural types would not need a bounds proposal or a () element type to stop implied repetition of the last element type

Ignoring questions of concrete syntax, this ticket asks for explicit rather than implicit repetition zero-or-more times for the last element type.

/be

Attachments

Change History

Changed 2 years ago by lth

  • owner set to lth
  • milestone set to M2

Make a joint proposal in the wiki with #68 and #69.

Changed 2 years ago by brendan

I wanted to add that the ability to type an empty array, constrained to be empty, is not useful and not something motivating this ticket. It's just a consequence, and IMHO a sane basis case, for the induction here.

/be

Changed 1 year ago by jorendorff

  • cc changed from lth,dherman,cormac,graydon,jeff to lth, dherman, cormac, graydon, jeff, jorendorff

Semantically, I think we do want both variable-length and fixed-length arrays. I'm not sure types like [String, Date, Fish...] are useful though. What if I want to iterate over the fish? I should probably be writing [String, Date, [Fish...]], right?

Changed 1 year ago by jorendorff

Syntactically, a proposal:

// --- Fixed-length array types
type NameValuePair = [String, *];
type ExampleTripleType = [Date, String, decimal];
// --- Variable-length array types
type ZeroOrMoreInts = Array.<int>;
// --- Or if syntax is desired:
type ZeroOrMoreInts = int[];

That syntax doesn't mean the same thing as in Java and C#, though, where arrays can't be resized; it's really more like Java's ArrayList<Integer>.

Changed 1 year ago by brendan

So we should probably have a discussion page linked from

https://intranet.mozilla.org/ECMA/wiki/doku.php?id=proposals:arrays

and talk there. That's the joint proposal in the wiki that lth's comment in this ticket was referencing.

/be

Changed 1 year ago by lth

See the array proposals page for an extended discussion and a possible fix; I won't update this proposal until we've debated there.

There is a discussion page attached to that page now. I've commented there on the reasons for not using the Array.<int> syntax (a proposal we've discussed several times in the past).

Changed 1 year ago by lth

  • component changed from Proposals to Spec

We have agreed (several times IIRC) that [t] means array and [t1,t2,...,tn] means tuple.

Changed 1 year ago by lth

  • priority changed from major to trivial
  • summary changed from Should array structural type syntax require explicit repetition to (Resolved) Should array structural type syntax require explicit repetition

Changed 7 months ago by airforce1

Note: See TracTickets for help on using tickets.