SIP-XX - Flexible Varargs

Posted a new SIP, take a look if you’re interested!

17 Likes

Seems small and good !

I don’t remember seeing a pre-sip for it however ?
(Which is technically required, although in this case the proposal seems straightforward enough ?)

Yeah it’s a simple enough change i decided to just write the markdown on the SIP website rather than writing it here and copy-pasting it later, can treat this thread as the pre-SIP w.r.t. discussing and critiquing it!

1 Like

Thanks for the heads up @lihaoyi! Happy to see a SIP that I love and don’t have to argue with :sweat_smile:

1 Like

This looks nice indeed, and does not require any deep insights in the language to use. It feels completely natural. Thank you for proposing this. :+1:

However, the point where you limit yourself to Seq and Option does not sound so convincing to me. If * means “expand some sequence” why should I (as user) care about the underlying type? I don’t want to know! And any .toSeq invalidates the simplicity of the proposal imho, apart from a possible impact on performance. So, make it more general and powerful by allowing this to work for any Iterable(once).

2 Likes

very nice! - there has been a student project at EPFL to implement something like this but unsure if the original author made it public

1 Like

A natural generalization would be to allow more than one star to unpack nested Seqs.

2 Likes

I think this SIP is good, because it addresses SIP-45’s issue to require the callee to have a signature that is different from ordinary vararg.

However, it is not as flexible as SIP-45, which allows for customizing the type to hold varargs. I suggest to summon a factory instance to create the builder via summon[scala.collection.Factory[A, S]].newBuilder instead of hard-coded IArray.newBuilder or Seq.newBuilder, given a vararg definition of:

def myFunction(vararg: A @ customVarargType[S] *) = ???

One can override newBuilder to return a richer type to preserve the element type information, in a custom scala.collection.Factory[A, S].

On JVM, the erased signature should be:

def myFunction(vararg: S) = ???

When the annotation customVarargType is omitted, it should behave like this:

def myFunction(vararg: A @ customVarargType[Seq[A]] *) = ???

So that the default behavior would be still backward compatible with existing ABI.

I’m not sure I understood everything you’re proposing, but this seems largely orthogonal to the current proposal ?

My suggestion is an add-on to this existing SIP, not orthogonal.

I think it would be more consistent if this SIP can merge with Pre-SIP: A Syntax for Collection Literals . It is common to use varargs in list literals in other languages.

Unfortunately, Pre-SIP: A Syntax for Collection Literals uses inline arguments, which seems incompatible with this SIP.

I don’t think we should merge these two SIPs, again they seem orthogonal (even though they have synergies)
But mostly because this one seems supported by everyone (and thus likely to pass), whereas the other is very divisive (and thus will potentially not)

3 Likes

Great improvement! The only problem I see - it may create more work for Intellij. And they still need more time to fix present scala 3 bugs

1 Like