Skip to content

Commit bfb0b81

Browse files
authored
Merge pull request #10826 from michelou/scala3-docs
[docs/reference] more fixes in Markdown files
2 parents 75365ea + 649be23 commit bfb0b81

37 files changed

+160
-122
lines changed

docs/docs/reference/changed-features/eta-expansion-spec.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ layout: doc-page
33
title: "Automatic Eta Expansion - More Details"
44
---
55

6-
### Motivation
6+
## Motivation
77

88
Scala maintains a convenient distinction between _methods_ and _functions_.
99
Methods are part of the definition of a class that can be invoked in objects while functions are complete objects themselves, making them first-class entities. For example, they can be assigned to variables.
10-
These two mechanisms are bridged in Scala by a mechanism called _eta-expansion_ (also called eta-abstraction), which converts a reference to a method into a function. Intuitively, a method `m` can be passed around by turning it into an object: the function `x => m(x)`.
10+
These two mechanisms are bridged in Scala by a mechanism called
11+
[_eta-expansion_](https://www.scala-lang.org/files/archive/spec/2.13/06-expressions.html#eta-expansion-section)
12+
(also called eta-abstraction), which converts a reference to a method into a function. Intuitively, a method `m` can be passed around by turning it into an object: the function `x => m(x)`.
1113

1214
In this snippet which assigns a method to a `val`, the compiler will perform _automatic eta-expansion_, as shown in the comment:
1315

@@ -69,6 +71,6 @@ Thus, an unapplied method with an empty argument list is only converted to a fun
6971

7072
The method value syntax `m _` is deprecated.
7173

72-
### Reference
74+
## Reference
7375

7476
For more info, see [PR #2701](https://github.com/lampepfl/dotty/pull/2701).

docs/docs/reference/changed-features/implicit-conversions-spec.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ The standard library defines an abstract class `Conversion`:
1616
```scala
1717
package scala
1818
@java.lang.FunctionalInterface
19-
abstract class Conversion[-T, +U] extends Function1[T, U]
19+
abstract class Conversion[-T, +U] extends Function1[T, U]:
20+
def apply(x: T): U
2021
```
2122

2223
Function literals are automatically converted to `Conversion` values.
@@ -80,8 +81,8 @@ implicit val myConverter: Int => String = _.toString
8081
implicit val myConverter: Conversion[Int, String] = _.toString
8182
```
8283

83-
Note that implicit conversions are also affected by the [changes to
84-
implicit resolution](implicit-resolution.md) between Scala 2 and
84+
Note that implicit conversions are also affected by the
85+
[changes to implicit resolution](implicit-resolution.md) between Scala 2 and
8586
Scala 3.
8687

8788
## Motivation for the changes

docs/docs/reference/changed-features/implicit-resolution.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: doc-page
33
title: "Changes in Implicit Resolution"
44
---
5-
This page describes changes to the implicit resolution that apply both to the new `given`s and to the old-style `implicit`s in Scala 3.
5+
This section describes changes to the implicit resolution that apply both to the new `given`s and to the old-style `implicit`s in Scala 3.
66
Implicit resolution uses a new algorithm which caches implicit results
77
more aggressively for performance. There are also some changes that
88
affect implicits on the language level.
@@ -20,8 +20,8 @@ where the type may still be inferred:
2020
/*!*/ implicit def y = ... // error: type must be given explicitly
2121

2222
val y = {
23-
implicit val ctx = this.ctx // ok
24-
...
23+
implicit val ctx = this.ctx // ok
24+
...
2525
}
2626
```
2727
**2.** Nesting is now taken into account for selecting an implicit. Consider for instance the following scenario:
@@ -114,7 +114,7 @@ the implicit search for `Q` fails.
114114
**5.** The treatment of divergence errors has also changed. A divergent implicit is treated as a normal failure, after which alternatives are still tried. This also makes sense: Encountering a divergent implicit means that we assume that no finite solution can be found on the corresponding path, but another path can still be tried. By contrast,
115115
most (but not all) divergence errors in Scala 2 would terminate the implicit search as a whole.
116116

117-
**6.** Scala-2 gives a lower level of priority to implicit conversions with call-by-name parameters relative to implicit conversions with call-by-value parameters. Scala 3 drops this distinction. So the following code snippet would be ambiguous in Scala 3:
117+
**6.** Scala 2 gives a lower level of priority to implicit conversions with call-by-name parameters relative to implicit conversions with call-by-value parameters. Scala 3 drops this distinction. So the following code snippet would be ambiguous in Scala 3:
118118

119119
```scala
120120
implicit def conv1(x: Int): A = new A(x)

docs/docs/reference/changed-features/pattern-matching.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def unapply[A](x: T)(implicit x: B): U
1616
def unapplySeq[A](x: T)(implicit x: B): U
1717
```
1818

19-
Extractors expose the method `unapply` are called fixed-arity extractors, which
20-
work with patterns of fixed arity. Extractors expose the method `unapplySeq` are
19+
Extractors that expose the method `unapply` are called fixed-arity extractors, which
20+
work with patterns of fixed arity. Extractors that expose the method `unapplySeq` are
2121
called variadic extractors, which enables variadic patterns.
2222

2323
### Fixed-Arity Extractors
@@ -93,7 +93,7 @@ A usage of a variadic extractor is irrefutable if one of the following condition
9393
## Boolean Match
9494

9595
- `U =:= Boolean`
96-
- Pattern-matching on exactly `0` patterns
96+
- Pattern-matching on exactly `0` pattern
9797

9898
For example:
9999

@@ -250,4 +250,4 @@ Abstract type testing with `ClassTag` is replaced with `TypeTest` or the alias `
250250
- pattern `_: X` for an abstract type requires a `TypeTest` in scope
251251
- pattern `x @ X()` for an unapply that takes an abstract type requires a `TypeTest` in scope
252252

253-
[More details on TypeTest](../other-new-features/type-test.md)
253+
[More details on `TypeTest`](../other-new-features/type-test.md)

docs/docs/reference/contextual/context-bounds.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A context bound is a shorthand for expressing the common pattern of a context pa
99
def maximum[T: Ord](xs: List[T]): T = xs.reduceLeft(max)
1010
```
1111

12-
A bound like `: Ord` on a type parameter `T` of a method or class indicates a context parameter `with Ord[T]`. The context parameter(s) generated from context bounds come last in the definition of the containing method or class. E.g.,
12+
A bound like `: Ord` on a type parameter `T` of a method or class indicates a context parameter `with Ord[T]`. The context parameter(s) generated from context bounds come last in the definition of the containing method or class. For instance,
1313

1414
```scala
1515
def f[T: C1 : C2, U: C3](x: T)(using y: U, z: V): R

docs/docs/reference/contextual/context-functions.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ object PostConditions {
125125

126126
def result[T](using r: WrappedResult[T]): T = r
127127

128-
extension [T](x: T) def ensuring(condition: WrappedResult[T] ?=> Boolean): T = {
129-
assert(condition(using x))
130-
x
131-
}
128+
extension [T](x: T)
129+
def ensuring(condition: WrappedResult[T] ?=> Boolean): T = {
130+
assert(condition(using x))
131+
x
132+
}
132133
}
133134
import PostConditions.{ensuring, result}
134135

docs/docs/reference/contextual/conversions.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ title: "Implicit Conversions"
66
Implicit conversions are defined by given instances of the `scala.Conversion` class.
77
This class is defined in package `scala` as follows:
88
```scala
9-
abstract class Conversion[-T, +U] extends (T => U)
9+
abstract class Conversion[-T, +U] extends (T => U):
10+
def apply (x: T): U
1011
```
1112
For example, here is an implicit conversion from `String` to `Token`:
1213
```scala
@@ -41,7 +42,7 @@ given int2Integer: Conversion[Int, java.lang.Integer] =
4142
java.lang.Integer.valueOf(_)
4243
```
4344

44-
2. The "magnet" pattern is sometimes used to express many variants of a method. Instead of defining overloaded versions of the method, one can also let the method take one or more arguments of specially defined "magnet" types, into which various argument types can be converted. E.g.
45+
2. The "magnet" pattern is sometimes used to express many variants of a method. Instead of defining overloaded versions of the method, one can also let the method take one or more arguments of specially defined "magnet" types, into which various argument types can be converted. Example:
4546
```scala
4647
object Completions {
4748

docs/docs/reference/contextual/derivation-macro.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,13 @@ The implementation of `summonAll` as a macro can be show below assuming that we
9191
have the given instances for our primitive types:
9292

9393
```scala
94-
def summonAll[T: Type](using Quotes): List[Expr[Eq[_]]] = Type.of[T] match {
95-
case '[String *: tpes] => '{ summon[Eq[String]] } :: summonAll[tpes]
96-
case '[Int *: tpes] => '{ summon[Eq[Int]] } :: summonAll[tpes]
97-
case '[tpe *: tpes] => derived[tpe] :: summonAll[tpes]
98-
case '[EmptyTuple] => Nil
99-
}
94+
def summonAll[T: Type](using Quotes): List[Expr[Eq[_]]] =
95+
Type.of[T] match {
96+
case '[String *: tpes] => '{ summon[Eq[String]] } :: summonAll[tpes]
97+
case '[Int *: tpes] => '{ summon[Eq[Int]] } :: summonAll[tpes]
98+
case '[tpe *: tpes] => derived[tpe] :: summonAll[tpes]
99+
case '[EmptyTuple] => Nil
100+
}
100101
```
101102

102103
One additional difference with the body of `derived` here as opposed to the one
@@ -169,12 +170,13 @@ object Eq {
169170
def eqv(x: T, y: T): Boolean = body(x, y)
170171
}
171172

172-
def summonAll[T: Type](using Quotes): List[Expr[Eq[_]]] = Type.of[T] match {
173-
case '[String *: tpes] => '{ summon[Eq[String]] } :: summonAll[tpes]
174-
case '[Int *: tpes] => '{ summon[Eq[Int]] } :: summonAll[tpes]
175-
case '[tpe *: tpes] => derived[tpe] :: summonAll[tpes]
176-
case '[EmptyTuple] => Nil
177-
}
173+
def summonAll[T: Type](using Quotes): List[Expr[Eq[_]]] =
174+
Type.of[T] match {
175+
case '[String *: tpes] => '{ summon[Eq[String]] } :: summonAll[tpes]
176+
case '[Int *: tpes] => '{ summon[Eq[Int]] } :: summonAll[tpes]
177+
case '[tpe *: tpes] => derived[tpe] :: summonAll[tpes]
178+
case '[EmptyTuple] => Nil
179+
}
178180

179181
given derived[T: Type](using q: Quotes): Expr[Eq[T]] = {
180182
import quotes.reflect._

docs/docs/reference/contextual/derivation.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,16 @@ object Mirror {
6363
/** The Mirror for a product type */
6464
trait Product extends Mirror {
6565

66-
/** Create a new instance of type `T` with elements taken from product `p`. */
66+
/** Create a new instance of type `T` with elements
67+
* taken from product `p`.
68+
*/
6769
def fromProduct(p: scala.Product): MirroredMonoType
6870
}
6971

7072
trait Sum extends Mirror { self =>
71-
/** The ordinal number of the case class of `x`. For enums, `ordinal(x) == x.ordinal` */
73+
/** The ordinal number of the case class of `x`.
74+
* For enums, `ordinal(x) == x.ordinal`
75+
*/
7276
def ordinal(x: MirroredMonoType): Int
7377
}
7478
}
@@ -199,10 +203,11 @@ implementation of `summonAll` is `inline` and uses Scala 3's `summonInline` cons
199203

200204
```scala
201205

202-
inline def summonAll[T <: Tuple]: List[Eq[_]] = inline erasedValue[T] match {
203-
case _: EmptyTuple => Nil
204-
case _: (t *: ts) => summonInline[Eq[t]] :: summonAll[ts]
205-
}
206+
inline def summonAll[T <: Tuple]: List[Eq[_]] =
207+
inline erasedValue[T] match {
208+
case _: EmptyTuple => Nil
209+
case _: (t *: ts) => summonInline[Eq[t]] :: summonAll[ts]
210+
}
206211
```
207212

208213
with the instances for children in hand the `derived` method uses an `inline match` to dispatch to methods which can
@@ -243,10 +248,11 @@ Pulling this all together we have the following complete implementation,
243248
import scala.deriving._
244249
import scala.compiletime.{erasedValue, summonInline}
245250

246-
inline def summonAll[T <: Tuple]: List[Eq[_]] = inline erasedValue[T] match {
247-
case _: EmptyTuple => Nil
248-
case _: (t *: ts) => summonInline[Eq[t]] :: summonAll[ts]
249-
}
251+
inline def summonAll[T <: Tuple]: List[Eq[_]] =
252+
inline erasedValue[T] match {
253+
case _: EmptyTuple => Nil
254+
case _: (t *: ts) => summonInline[Eq[t]] :: summonAll[ts]
255+
}
250256

251257
trait Eq[T] {
252258
def eqv(x: T, y: T): Boolean

docs/docs/reference/contextual/extension-methods.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ object List:
215215
def < (ys: List[T]): Boolean = ...
216216
end List
217217

218-
// extension method available since it is in the implicit scope of List[List[Int]]
218+
// extension method available since it is in the implicit scope
219+
// of List[List[Int]]
219220
List(List(1, 2), List(3, 4)).flatten
220221

221222
// extension method available since it is in the given Ordering[List[T]],

0 commit comments

Comments
 (0)