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/contextual-implicit/inferable-by-name-parameters.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ The precise steps for synthesizing an argument for a by-name parameter of type `
40
40
```
41
41
where `lv` is an arbitrary fresh name.
42
42
43
-
1. Thisimplicit is not immediately available ascandidatefor argument inference (making it immediately available could result in a loop in the synthesized computation). But it becomes available in all nested contexts that look again for an implicit argument to a by-name parameter.
43
+
1. Thisimplicit is not immediately available asacandidate for argument inference (making it immediately available could result in a loop in the synthesized computation). But it becomes available in all nested contexts that look again for an implicit argument to a by-name parameter.
44
44
45
45
1. Ifthis search succeeds with expression `E`, and `E` contains references to the implicit `lv`, replace `E` by
Copy file name to clipboardExpand all lines: docs/docs/reference/contextual-implicit/inferable-params.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ max(List(1, 2, 3), Nil)
30
30
31
31
## Anonymous Implicit Parameters
32
32
33
-
In many situations, the name of an implicit parameter of a method need not be mentioned explicitly at all, since it is only used as synthesized implicit for other constraints. In that case one can avoid defining a parameter name and just provide its type. Example:
33
+
In many situations, the name of an implicit parameter of a method need not be mentioned explicitly at all, since it is only used as a synthesized argument for other implicit parameters. In that case one can avoid defining a parameter name and just provide its type. Example:
Copy file name to clipboardExpand all lines: docs/docs/reference/contextual-implicit/relationship-implicits.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
@@ -140,11 +140,11 @@ one can write
140
140
141
141
### Implicit Classes
142
142
143
-
Implicit classes in Scala 2 are often used to define extension methods, which are directly supported in Dotty. Other uses of implicit classes can be simulated by a pair of a regular class and a conversion delegate.
143
+
Implicit classes in Scala 2 are often used to define extension methods, which are directly supported in Dotty. Other uses of implicit classes can be simulated by a pair of a regular class and a conversion instance.
144
144
145
145
### Abstract Implicits
146
146
147
-
An abstract implicit `val` or `def` in Scala 2 can be expressed in Dotty using a regular abstract definition and an implicit alias. E.g., Scala 2's
147
+
An abstract implicit `val` or `def` in Scala 2 can be expressed in Dotty using a regular abstract definition and an alias implicit. E.g., Scala 2's
Besides for `enums`, typeclasses can also be derived for other sets of classes and objects that form an algebraic data type. These are:
22
+
Besides for enums, typeclasses can also be derived for other sets of classes and objects that form an algebraic data type. These are:
23
23
24
24
- individual case classes or case objects
25
25
- sealed classes or traits that have only case classes and case objects as children.
@@ -93,8 +93,7 @@ is represented as `T *: Unit` since there is no direct syntax for such tuples: `
93
93
94
94
### The Generic Typeclass
95
95
96
-
For every class `C[T_1,...,T_n]` with a `derives` clause, the compiler generates in the companion object of `C` an representative of `Generic[C[T_1,...,T_n]]` that follows
97
-
the outline below:
96
+
For every class `C[T_1,...,T_n]` with a `derives` clause, the compiler generates in the companion object of `C` a representative of `Generic[C[T_1,...,T_n]]` that follows the outline below:
98
97
```scala
99
98
repr [T_1, ..., T_n] of Generic[C[T_1,...,T_n]] {
100
99
typeShape= ...
@@ -215,7 +214,7 @@ trait Eql[T] {
215
214
}
216
215
```
217
216
We need to implement a method `Eql.derived` that produces a representative of `Eql[T]` provided
218
-
there exists evidence of type `Generic[T]`. Here's a possible solution:
217
+
there exists a representative of type `Generic[T]`. Here's a possible solution:
219
218
```scala
220
219
inlinedefderived[T] given (ev: Generic[T]):Eql[T] =newEql[T] {
221
220
defeql(x: T, y: T):Boolean= {
@@ -234,7 +233,7 @@ there exists evidence of type `Generic[T]`. Here's a possible solution:
234
233
The implementation of the inline method `derived` creates a representative of `Eql[T]` and implements its `eql` method. The right-hand side of `eql` mixes compile-time and runtime elements. In the code above, runtime elements are marked with a number in parentheses, i.e
235
234
`(1)`, `(2)`, `(3)`. Compile-time calls that expand to runtime code are marked with a number in brackets, i.e. `[4]`, `[5]`. The implementation of `eql` consists of the following steps.
236
235
237
-
1. Map the compared values `x` and `y` to their mirrors using the `reflect` method of the implicitly passed `Generic`evidence `(1)`, `(2)`.
236
+
1. Map the compared values `x` and `y` to their mirrors using the `reflect` method of the implicitly passed `Generic``(1)`, `(2)`.
238
237
2. Match at compile-time against the shape of the ADT given in `ev.Shape`. Dotty does not have a construct for matching types directly, but we can emulate it using an `inline` match over an `erasedValue`. Depending on the actual type `ev.Shape`, the match will reduce at compile time to one of its two alternatives.
239
238
3. If `ev.Shape` is of the form `Cases[alts]` for some tuple `alts` of alternative types, the equality test consists of comparing the ordinal values of the two mirrors `(3)` and, if they are equal, comparing the elements of the case indicated by that ordinal value. That second step is performed by code that results from the compile-time expansion of the `eqlCases` call `[4]`.
240
239
4. If `ev.Shape` is of the form `Case[elems]` for some tuple `elems` for element types, the elements of the case are compared by code that results from the compile-time expansion of the `eqlElems` call `[5]`.
@@ -302,7 +301,7 @@ The last, and in a sense most interesting part of the derivation is the comparis
302
301
caseev: Eql[T] =>
303
302
ev.eql(x, y) // (15)
304
303
case _ =>
305
-
error("No `Eql` representative was found for $T")
304
+
error("No `Eql` instance was found for $T")
306
305
}
307
306
```
308
307
`tryEql` is an inline method that takes an element type `T` and two element values of that type as arguments. It is defined using an `implicit match` that tries to find a representative of `Eql[T]`. If a representative `ev` is found, it proceeds by comparing the arguments using `ev.eql`. On the other hand, if no representative is found
Copy file name to clipboardExpand all lines: docs/docs/reference/contextual-repr/extension-methods.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,7 @@ Then
56
56
```scala
57
57
List("here", "is", "a", "list").longestStrings
58
58
```
59
-
is legal everywhere `ops1` is available as a representative. Alternatively, we can define `longestStrings` as a member of a normal object. But then the method has to be brought into scope to be usable as an extension method.
59
+
is legal everywhere `ops1` is eligible. Alternatively, we can define `longestStrings` as a member of a normal object. But then the method has to be brought into scope to be usable as an extension method.
60
60
61
61
```scala
62
62
objectops2extendsStringSeqOps
@@ -80,7 +80,7 @@ So `circle.circumference` translates to `CircleOps.circumference(circle)`, provi
80
80
81
81
### Representatives for Extension Methods
82
82
83
-
Representatives that define extension methods can also be defined without a `for` clause. E.g.,
83
+
Representatives that define extension methods can also be defined without an `of` clause. E.g.,
84
84
85
85
```scala
86
86
repr StringOps {
@@ -94,12 +94,12 @@ repr {
94
94
def (xs: List[T]) second[T] = xs.tail.head
95
95
}
96
96
```
97
-
If such representatives are anonymous (as in the second clause), their name is synthesized from the name
97
+
If such a representative is anonymous (as in the second clause), its name is synthesized from the name
98
98
of the first defined extension method.
99
99
100
100
### Operators
101
101
102
-
The extension method syntax also applies to the definitions of operators.
102
+
The extension method syntax also applies to the definition of operators.
103
103
In each case the definition syntax mirrors the way the operator is applied.
Copy file name to clipboardExpand all lines: docs/docs/reference/contextual-repr/import-implied.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ object B {
18
18
In the code above, the `import A._` clause of object `B` will import all members
19
19
of `A`_except_ the representative `tc`. Conversely, the second import `import repr A._` will import _only_ that representative.
20
20
21
-
Generally, a normal import clause brings all definitions except representatives into scope whereas an `import repr` clause brings only representatives into scope.
21
+
Generally, a normal import clause brings all members except representatives into scope whereas an `import repr` clause brings only representatives into scope.
22
22
23
23
There are two main benefits arising from these rules:
24
24
@@ -29,7 +29,7 @@ There are two main benefits arising from these rules:
29
29
can be anonymous, so the usual recourse of using named imports is not
30
30
practical.
31
31
32
-
### Relationship with Old-Style Implicits
32
+
### Migration
33
33
34
34
The rules of representatives above have the consequence that a library
35
35
would have to migrate in lockstep with all its users from old style implicits and
@@ -49,4 +49,4 @@ The following modifications avoid this hurdle to migration.
49
49
50
50
These rules mean that library users can use `import repr` to access old-style implicits in Scala 3.0,
51
51
and will be gently nudged and then forced to do so in later versions. Libraries can then switch to
52
-
representation clauses once their user base has migrated.
Copy file name to clipboardExpand all lines: docs/docs/reference/contextual-repr/inferable-by-name-parameters.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ The precise steps for synthesizing an argument for a by-name parameter of type `
40
40
```
41
41
where `lv` is an arbitrary fresh name.
42
42
43
-
1. This representative is not immediately availableascandidatefor argument inference (making it immediately available could result in a loop in the synthesized computation). But it becomes available in all nested contexts that look again for an argument to an implicit by-name parameter.
43
+
1. This representative is not immediately eligibleasacandidate for argument inference (making it immediately eligible could result in a loop in the synthesized computation). But it becomes eligible in all nested contexts that look again for an implicitargument to a by-name parameter.
44
44
45
45
1. Ifthis search succeeds with expression `E`, and `E` contains references to the representative `lv`, replace `E` by
0 commit comments