You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/reference/enums/enums.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,9 +95,10 @@ If you want to use the Scala-defined enums as Java enums, you can do so by exten
95
95
enumColorextends java.lang.Enum[Color] { caseRed, Green, Blue }
96
96
```
97
97
98
-
The type parameter comes from the Java enum [definition](https://docs.oracle.com/javase/8/docs/api/index.html?java/lang/Enum.html) and should be the same as the type of the enum. There is no need to provide constructor arguments (as defined in the API docs) to `java.lang.Enum` when extending it – the compiler will generate them automatically.
98
+
The type parameter comes from the Java enum [definition](https://docs.oracle.com/javase/8/docs/api/index.html?java/lang/Enum.html) and should be the same as the type of the enum.
99
+
There is no need to provide constructor arguments (as defined in the Java API docs) to `java.lang.Enum` when extending it – the compiler will generate them automatically.
99
100
100
-
After defining `Color` like that, you can use like you would a Java enum:
101
+
After defining `Color` like that, you can use it like you would a Java enum:
Copy file name to clipboardExpand all lines: docs/docs/reference/new-types/match-types.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,7 @@ S match { P1 => T1 ... Pn => Tn }
54
54
```
55
55
is `Match(S, C1, ..., Cn) <: B` where each case `Ci` is of the form
56
56
```
57
-
[Xs] => P => T
57
+
[Xs] =>> P => T
58
58
```
59
59
Here, `[Xs]` is a type parameter clause of the variables bound in pattern `Pi`. If there are no bound type variables in a case, the type parameter clause is omitted and only the function type `P => T` is kept. So each case is either a unary function type or a type lambda over a unary function type.
60
60
@@ -68,7 +68,7 @@ We define match type reduction in terms of an auxiliary relation, `can-reduce`:
68
68
```
69
69
Match(S, C1, ..., Cn) can-reduce i, T'
70
70
```
71
-
if `Ci = [Xs] => P => T` and there are minimal instantiations `Is` of the type variables `Xs` such that
71
+
if `Ci = [Xs] =>> P => T` and there are minimal instantiations `Is` of the type variables `Xs` such that
Copy file name to clipboardExpand all lines: docs/docs/reference/other-new-features/opaques.md
+15-16Lines changed: 15 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,8 @@ object Logarithms {
12
12
13
13
objectLogarithm {
14
14
15
-
// These are the ways to lift to the logarithm type
15
+
// These are the two ways to lift to the Logarithm type
16
+
16
17
defapply(d: Double):Logarithm= math.log(d)
17
18
18
19
defsafe(d: Double):Option[Logarithm] =
@@ -28,19 +29,19 @@ object Logarithms {
28
29
}
29
30
```
30
31
31
-
This introduces `Logarithm` as a new type, which is implemented as `Double` but is different from it. The fact that `Logarithm` is the same as `Double` is only known in the scope where
32
-
`Logarithm` is defined which in this case is object `Logarithms`.
33
-
34
-
The public API of `Logarithm` consists of the `apply` and `safe` methods that convert from doubles to `Logarithm` values, an extension method `toDouble` that converts the other way,
35
-
and operations `+` and `*` on logarithm values. The implementations of these functions
36
-
type-check because within object `Logarithms`, the type `Logarithm` is just an alias of `Double`.
32
+
This introduces `Logarithm` as a new abstract type, which is implemented as `Double`.
33
+
The fact that `Logarithm` is the same as `Double` is only known in the scope where
34
+
`Logarithm` is defined which in the above example corresponds to the object `Logarithms`.
35
+
Or in other words, within the scope it is treated as type alias, but this is opaque to the outside world
36
+
where in consequence `Logarithm` is seen as an abstract type and has nothing to do with `Double`.
37
37
38
-
Outside its scope, `Logarithm` is treated as a new abstract type. So the
39
-
following operations would be valid because they use functionality implemented in the `Logarithm` object.
38
+
The public API of `Logarithm` consists of the `apply` and `safe` methods defined in the companion object.
39
+
They convert from `Double`s to `Logarithm` values. Moreover, a collective extension `logarithmOps` provides the extension methods `toDouble` that converts the other way,
40
+
and operations `+` and `*` on `Logarithm` values.
41
+
The following operations would be valid because they use functionality implemented in the `Logarithms` object.
40
42
41
43
```scala
42
-
importLogarithms._
43
-
importPredef.{any2stringadd=>_, _}
44
+
importLogarithms.Logarithm
44
45
45
46
vall=Logarithm(1.0)
46
47
vall2=Logarithm(2.0)
@@ -54,11 +55,9 @@ But the following operations would lead to type errors:
54
55
vald:Double= l // error: found: Logarithm, required: Double
Aside: the `any2stringadd => _` import suppression is necessary since otherwise the universal `+` operation in `Predef` would take precedence over the `+` extension method in `logarithmOps`. We plan to resolve this wart by eliminating `any2stringadd`.
61
-
62
61
### Bounds For Opaque Type Aliases
63
62
64
63
Opaque type aliases can also come with bounds. Example:
@@ -81,7 +80,7 @@ object Access {
81
80
valReadOrWrite:PermissionChoice=Read|Write
82
81
}
83
82
```
84
-
The `Access` object defines three opaque types:
83
+
The `Access` object defines three opaque type aliases:
85
84
86
85
-`Permission`, representing a single permission,
87
86
-`Permissions`, representing a set of permissions with the meaning "all of these permissions granted",
@@ -98,7 +97,7 @@ Because of that, the `|` extension method in `Access` does not cause infinite re
98
97
Also, the definition of `ReadWrite` must use `|`,
99
98
even though an equivalent definition outside `Access` would use `&`.
100
99
101
-
All three opaque types have the same underlying representation type `Int`. The
100
+
All three opaque type aliases have the same underlying representation type `Int`. The
102
101
`Permission` type has an upper bound `Permissions & PermissionChoice`. This makes
103
102
it known outside the `Access` object that `Permission` is a subtype of the other
104
103
two types. Hence, the following usage scenario type-checks.
0 commit comments