Skip to content

Commit b38fa72

Browse files
Merge pull request #2699 from Varunram/singleton-types
Add doc page for Literal Singleton Types
2 parents c804620 + 3d0abce commit b38fa72

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
layout: doc-page
3+
title: "Literal Singleton Types"
4+
---
5+
6+
Literal Singleton Types allows primitive literals to be used as types. For example:
7+
8+
```scala
9+
val t: 42 = 42
10+
val x: "Jedi" = "Jedi"
11+
```
12+
13+
It is also possible to define functions returning or taking singleton types such as
14+
15+
```scala
16+
def f(t: Double): t.type = t
17+
val a: 1.2 = f(1.2)
18+
```
19+
20+
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)

docs/sidebar.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ sidebar:
2727
url: docs/reference/implicit-function-types.html
2828
- title: Phantom Types
2929
url: docs/reference/phantom-types.html
30+
- title: Literal Singleton Types
31+
url: docs/reference/singleton-types.html
3032
- title: Enums
3133
subsection:
3234
- title: Enumerations

0 commit comments

Comments
 (0)