diff --git a/docs/docs/reference/singleton-types.md b/docs/docs/reference/singleton-types.md new file mode 100644 index 000000000000..ec1485848010 --- /dev/null +++ b/docs/docs/reference/singleton-types.md @@ -0,0 +1,20 @@ +--- +layout: doc-page +title: "Literal Singleton Types" +--- + +Literal Singleton Types allows primitive literals to be used as types. For example: + +```scala +val t: 42 = 42 +val x: "Jedi" = "Jedi" +``` + +It is also possible to define functions returning or taking singleton types such as + +```scala +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](http://docs.scala-lang.org/sips/pending/42.type.html) diff --git a/docs/sidebar.yml b/docs/sidebar.yml index 1ff62788a7bd..6fc871c8a6e6 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -27,6 +27,8 @@ sidebar: url: docs/reference/implicit-function-types.html - title: Phantom Types url: docs/reference/phantom-types.html + - title: Literal Singleton Types + url: docs/reference/singleton-types.html - title: Enums subsection: - title: Enumerations