Singleton subtyping, and can we mark scala.Singleton as experimental?

Just to try to draw out something actionable before diving further into alt-designs, do we all agree that the current incarnation of Singleton as an upper bound should be marked experimental for the 2.13 release, while these alt-designs cook?

1 Like

Thatā€™s part of SIP23 which was approved (and already used is some projects). Personally, I would rather any changes in this concept are passed through a SIP process, including a deprecation/language flag.

Iā€™m not sure whatā€™s special about 2.13 here, scala.Singleton has existed and has had this behavior since before 2.13.

:man_facepalming: wow, I did not know this, sorry folks

Or even bolder! Explicit kinds :slight_smile: (sneaking them in through a magic context bound?)

def foo[T: Kind[Singleton]](t: T) = ...
3 Likes

I do like the idea of a magic context bounds, itā€™s the closest Iā€™ve seen to Milesā€™ desire for a general purpose elaboration mechanism.

I recant my idea of a caret in the same position as +/- and instead give youā€¦ elaboration bounds

def foo[T ^ Singleton](t: T) = ... 

Just as bold, but slightly less magical.

Given how commonly ^ is used for higher-kinded multiplication (a.k.a exponentiation), I like how the intuition works on this.

CPS did that for return types, for type parameters (e.g. @specialized) itā€™s a prefix.

Iā€™m not sure, if the only way to define an ā€œelaboration boundā€ is by hardcoding its behavior in the compiler, then the syntax you propose doesnā€™t seem any better than using a keyword for each hardcoded behavior, and it raises more questions, like whatā€™s Singleton ? Is it a type ? If so, what are the values of this type ? etc.

3 Likes