Pre-SIP: A Syntax for Collection Literals

If Scala is going to get [] for collection literals, why wouldn’t go a step further and make it a new better syntax for tuple literals?

How come it can be better?

  1. Tuples are collections already, so collections would be covered automatically.
  2. It would also solve the long-overdue issue with the current tuple literal syntax – it would allow to declare empty and 1-item tuples consistently without clumsy workarounds (like (,) and (a,)):
    • [] – empty tuple;
    • [a] – 1-item tuple;
    • [a,b] – 2-items tuple and so forth.
  3. Perhaps(!), it might also be possible to go even further, and unify tuple literals and tuple type definitions:
    type T0 = []
    type T1 = [Int]
    type T2 = [Int, String]
    
    which in turn would solve the other issue raised in this topic:

So it seems that [] for tuples could bring far more improvements than just a convenience syntax for collections (which to me does not seem really important).

1 Like