File tree Expand file tree Collapse file tree 2 files changed +5
-10
lines changed
docs/docs/reference/new-types Expand file tree Collapse file tree 2 files changed +5
-10
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ treatment of singleton types which are also widened to their underlying type
8888unless explicitly specified. and the motivation is the same: inferring types
8989which are "too precise" can lead to unintuitive typechecking issues later on.
9090
91- Note: Since this behavior severely limits the usability of union types, it might
91+ Note: Since this behavior limits the usability of union types, it might
9292be changed in the future. For example by not widening unions that have been
9393explicitly written down by the user and not inferred, or by not widening a type
9494argument when the corresponding type parameter is covariant. See
@@ -149,7 +149,3 @@ the erased lub is computed as follows:
149149 The reason to pick last is that we prefer classes over traits that way,
150150 which leads to more predictable bytecode and (?) faster dynamic dispatch.
151151
152- ## Limitations
153-
154- In a union type ` A | B ` , neither ` A ` nor ` B ` is allowed to be a singleton type.
155- This is an implementation restriction that may be lifted in the future.
Original file line number Diff line number Diff line change @@ -3,7 +3,8 @@ layout: doc-page
33title : " Union Types"
44---
55
6- Used on types, the ` | ` operator creates a union type.
6+ A union type ` A | B ` has as values all values of type ` A ` and also all values of type ` B ` .
7+
78
89``` scala
910case class UserName (name : String ) {
@@ -22,13 +23,11 @@ def help(id: UserName | Password) = {
2223}
2324```
2425
25- Union types are dual of intersection types. Values of type ` A | B ` are
26- all values of type ` A ` and all values of type ` B ` . ` | ` is _ commutative_ :
26+ Union types are duals of intersection types. ` | ` is _ commutative_ :
2727` A | B ` is the same type as ` B | A ` .
2828
2929The compiler will assign a union type to an expression only if such a
30- type is explicitly given.
31- This can be seen in the following REPL transcript:
30+ type is explicitly given. This can be seen in the following REPL transcript:
3231
3332``` scala
3433scala> val password = Password (123 )
You can’t perform that action at this time.
0 commit comments