Dotty Documentation


Literal Singleton Types

Edit this page on GitHub

Literal Singleton Types allow primitive literals to be used as types. For example:

val t: 42 = 42
val x: "Jedi" = "Jedi"

It is also possible to define functions returning or taking singleton types such as

def f(t: Double): t.type = t
val a: 1.2 = f(1.2)

For more details and the motivation behind the need for literal singleton types, check out SIP-23