Skip to content

Commit 95eeacc

Browse files
authored
Merge pull request #8507 from tegonal/documation
different documation improvments
2 parents 7faf6f2 + 1582216 commit 95eeacc

File tree

9 files changed

+39
-40
lines changed

9 files changed

+39
-40
lines changed

docs/docs/reference/contextual/givens.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ a given for the type `Ord[Int]` whereas `listOrd[T]` defines givens
3434
for `Ord[List[T]]` for all types `T` that come with a given instance for `Ord[T]`
3535
themselves. The `using` clause in `listOrd` defines a condition: There must be a
3636
given of type `Ord[T]` for a given of type `List[Ord[T]]` to exist.
37-
Such conditions are expanded by the compiler to context
38-
parameters, which are explained in the [next section](./using-clauses.html).
37+
Such conditions are expanded by the compiler to [context
38+
parameters](./using-clauses.html).
3939

4040
## Anonymous Givens
4141

@@ -57,14 +57,15 @@ given global as ExecutionContext = new ForkJoinPool()
5757
This creates a given `global` of type `ExecutionContext` that resolves to the right
5858
hand side `new ForkJoinPool()`.
5959
The first time `global` is accessed, a new `ForkJoinPool` is created, which is then
60-
returned for this and all subsequent accesses to `global`.
60+
returned for this and all subsequent accesses to `global`. This operation is thread-safe.
6161

62-
Alias givens can be anonymous, e.g.
62+
Alias givens can be anonymous as well, e.g.
6363
```scala
6464
given Position = enclosingTree.position
65-
given (using outer: Context) as Context = outer.withOwner(currentOwner)
65+
given (using config: Config) as Factory = MemoizingFactory(config)
6666
```
67-
An alias given can have type parameters and implicit parameters just like any other given,
67+
68+
An alias given can have type parameters and context parameters just like any other given,
6869
but it can only implement a single type.
6970

7071
## Given Whitebox Macro Instances

docs/docs/reference/enums/adts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ layout: doc-page
33
title: "Algebraic Data Types"
44
---
55

6-
The `enum` concept is general enough to also support algebraic data
7-
types (ADTs) and their generalized version (GADTs). Here's an example
6+
The [`enum` concept](./enums.html) is general enough to also support algebraic data
7+
types (ADTs) and their generalized version (GADTs). Here is an example
88
how an `Option` type can be represented as an ADT:
99

1010
```scala
@@ -34,7 +34,7 @@ Note that the parent type of the `None` value is inferred as
3434
`Option[Nothing]`. Generally, all covariant type parameters of the enum
3535
class are minimized in a compiler-generated extends clause whereas all
3636
contravariant type parameters are maximized. If `Option` was non-variant,
37-
you'd need to give the extends clause of `None` explicitly.
37+
you would need to give the extends clause of `None` explicitly.
3838

3939
As for normal enum values, the cases of an `enum` are all defined in
4040
the `enum`s companion object. So it's `Option.Some` and `Option.None`

docs/docs/reference/enums/enums.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ If you want to use the Scala-defined enums as Java enums, you can do so by exten
9595
enum Color extends java.lang.Enum[Color] { case Red, Green, Blue }
9696
```
9797

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.
99100

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:
101102

102103
```scala
103104
scala> Color.Red.compareTo(Color.Green)

docs/docs/reference/new-types/dependent-function-types-spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ FunctionN[K1, ..., Kn, R'] {
3131
```
3232

3333
where the result type parameter `R'` is the least upper approximation of the
34-
precise result type `R` without any referance to value parameters `x1, ..., xN`.
34+
precise result type `R` without any reference to value parameters `x1, ..., xN`.
3535

3636
The syntax and sementics of anonymous dependent functions is identical to the
3737
one of regular functions. Eta expansion is naturally generalized to produce

docs/docs/reference/new-types/match-types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ S match { P1 => T1 ... Pn => Tn }
5454
```
5555
is `Match(S, C1, ..., Cn) <: B` where each case `Ci` is of the form
5656
```
57-
[Xs] => P => T
57+
[Xs] =>> P => T
5858
```
5959
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.
6060

@@ -68,7 +68,7 @@ We define match type reduction in terms of an auxiliary relation, `can-reduce`:
6868
```
6969
Match(S, C1, ..., Cn) can-reduce i, T'
7070
```
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
7272
```
7373
S <: [Xs := Is] P
7474
T' = [Xs := Is] T

docs/docs/reference/new-types/type-lambdas-spec.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ TypeBounds ::= [‘>:’ Type] [‘<:’ Type]
1414

1515
### Type Checking
1616

17-
A type lambda such as `[X] =>> F[X]` defines a function from types to types. The parameter(s) may carry bounds and variance annotations.
18-
If a parameter is bounded, as in `[X >: L <: H] =>> F[X]` it is checked that arguments to the parameters conform to the bounds `L` and `H`.
19-
Only the upper bound `H` can be F-bounded, i.e. `X` can appear in it.
17+
A type lambda such as `[X] =>> F[X]` defines a function from types to types. The parameter(s) may carry bounds.
18+
If a parameter is bounded, as in `[X >: L <: U] =>> F[X]` it is checked that arguments to the parameters conform to the bounds `L` and `U`.
19+
Only the upper bound `U` can be F-bounded, i.e. `X` can appear in it.
2020

2121
## Subtyping Rules
2222

@@ -31,7 +31,7 @@ Then `TL1 <: TL2`, if
3131
`L1 <: L2` and `U2 <: U1`),
3232
- `R1 <: R2`
3333

34-
Here we have relied on alpha renaming to bring match the two bound types `X`.
34+
Here we have relied on alpha renaming to match the two bound types `X`.
3535

3636
A partially applied type constructor such as `List` is assumed to be equivalent to
3737
its eta expansion. I.e, `List = [X] =>> List[X]`. This allows type constructors to be compared with type lambdas.
@@ -46,7 +46,7 @@ is regarded as a shorthand for an unparameterized definition with a type lambda
4646
```scala
4747
type T = [X] =>> R
4848
```
49-
If the a type definition carries `+` or `-` variance annotations,
49+
If the type definition carries `+` or `-` variance annotations,
5050
it is checked that the variance annotations are satisfied by the type lambda.
5151
For instance,
5252
```scala

docs/docs/reference/new-types/type-lambdas.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ a type definition.
1010
[X, Y] =>> Map[Y, X]
1111
```
1212

13-
For instance, the type above defines a binary type constructor, which
14-
constructor maps arguments `X` and `Y` to `Map[Y, X]`. Type parameters
15-
of type lambdas can have bounds but they cannot carry `+` or `-` variance
16-
annotations.
13+
For instance, the type above defines a binary type constructor, which maps arguments `X` and `Y` to `Map[Y, X]`.
14+
Type parameters of type lambdas can have bounds but they cannot carry `+` or `-` variance annotations.
1715

1816
[More details](./type-lambdas-spec.md)

docs/docs/reference/other-new-features/opaques-details.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ where the lower bound `L` and the upper bound `U` may be missing, in which case
2525
Inside the scope of the alias definition, the alias is transparent: `T` is treated
2626
as a normal alias of `R`. Outside its scope, the alias is treated as the abstract type
2727
```scala
28-
type T >: L <: U`
28+
type T >: L <: U
2929
```
3030
A special case arises if the opaque type is defined in an object. Example:
3131
```

docs/docs/reference/other-new-features/opaques.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ object Logarithms {
1212

1313
object Logarithm {
1414

15-
// These are the ways to lift to the logarithm type
15+
// These are the two ways to lift to the Logarithm type
16+
1617
def apply(d: Double): Logarithm = math.log(d)
1718

1819
def safe(d: Double): Option[Logarithm] =
@@ -28,19 +29,19 @@ object Logarithms {
2829
}
2930
```
3031

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`.
3737

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.
4042

4143
```scala
42-
import Logarithms._
43-
import Predef.{any2stringadd => _, _}
44+
import Logarithms.Logarithm
4445

4546
val l = Logarithm(1.0)
4647
val l2 = Logarithm(2.0)
@@ -54,11 +55,9 @@ But the following operations would lead to type errors:
5455
val d: Double = l // error: found: Logarithm, required: Double
5556
val l2: Logarithm = 1.0 // error: found: Double, required: Logarithm
5657
l * 2 // error: found: Int(2), required: Logarithm
57-
l / l2 // error: `/` is not a member fo Logarithm
58+
l / l2 // error: `/` is not a member of Logarithm
5859
```
5960

60-
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-
6261
### Bounds For Opaque Type Aliases
6362

6463
Opaque type aliases can also come with bounds. Example:
@@ -81,7 +80,7 @@ object Access {
8180
val ReadOrWrite: PermissionChoice = Read | Write
8281
}
8382
```
84-
The `Access` object defines three opaque types:
83+
The `Access` object defines three opaque type aliases:
8584

8685
- `Permission`, representing a single permission,
8786
- `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
9897
Also, the definition of `ReadWrite` must use `|`,
9998
even though an equivalent definition outside `Access` would use `&`.
10099

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
102101
`Permission` type has an upper bound `Permissions & PermissionChoice`. This makes
103102
it known outside the `Access` object that `Permission` is a subtype of the other
104103
two types. Hence, the following usage scenario type-checks.

0 commit comments

Comments
 (0)