From 9914606f4a00ba164f60fdac6954b04872597e66 Mon Sep 17 00:00:00 2001 From: Varunram Ganesh Date: Wed, 7 Jun 2017 16:17:38 +0530 Subject: [PATCH 1/3] Create new doc page for Literal Singleton Types --- docs/docs/reference/singleton-types.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 docs/docs/reference/singleton-types.md diff --git a/docs/docs/reference/singleton-types.md b/docs/docs/reference/singleton-types.md new file mode 100644 index 000000000000..6f310ced3bdb --- /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 t: "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) From 491b2fad0f608fd4648efc212806beb9943526ca Mon Sep 17 00:00:00 2001 From: Varunram Ganesh Date: Wed, 7 Jun 2017 16:18:33 +0530 Subject: [PATCH 2/3] Added Sidebar Entry for Singleton Types --- docs/sidebar.yml | 2 ++ 1 file changed, 2 insertions(+) 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 From 3d0abcea21f158fd9586a626081531328d9aadef Mon Sep 17 00:00:00 2001 From: Varunram Ganesh Date: Wed, 7 Jun 2017 18:08:49 +0530 Subject: [PATCH 3/3] Change name of variable --- docs/docs/reference/singleton-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/reference/singleton-types.md b/docs/docs/reference/singleton-types.md index 6f310ced3bdb..ec1485848010 100644 --- a/docs/docs/reference/singleton-types.md +++ b/docs/docs/reference/singleton-types.md @@ -7,7 +7,7 @@ Literal Singleton Types allows primitive literals to be used as types. For examp ```scala val t: 42 = 42 -val t: "Jedi" = "Jedi" +val x: "Jedi" = "Jedi" ``` It is also possible to define functions returning or taking singleton types such as