Syntactic sugar for Tuple1


#1

Why don’t we have a syntactic sugar for Tuple1[A]? This could potentially be useful since in Dotty, Tuples are HLists, so Tuple1 might be encountered when writing typeful metaprogramming stuff.

Python has (a,) as syntax for creating tuples of 1 element. Why don’t we create the following syntactic sugar for Dotty?

/*type-level*/   (A,)   =:=   Tuple1[A]
/*value-level*/  (a,)    :    (A,)

#2

Hmm. One the one hand, I don’t find the (a,) syntax for a Tuple1 all that intuitive, personally. OTOH, TIL it is exactly the way it gets toString’ed:

Tuple1("hello")
res1: (String,) = (hello,)

So there’s a consistency argument in favor of adding this…


#3

We could do it, but I am not sure we need to. We already have

   A *: ()    =    Tuple1[A]
   a *: ()    =    Tuple1(a)

Given that 1-tuples are most useful in a context where you go over tuples generically, and that *:(i.e. HLIst-cons) is the essential building block in that context, I am not sure we need additional syntax.


#4

Ah I don’t know this! Thanks :slight_smile: