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]],

docs/docs/reference/contextual/motivation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: "Overview"
77

88
Scala's implicits are its most distinguished feature. They are _the_ fundamental way to abstract over context. They represent a unified paradigm with a great variety of use cases, among them: implementing type classes, establishing context, dependency injection, expressing capabilities, computing new types and proving relationships between them.
99

10-
Following Haskell, Scala was the second popular language to have some form of implicits. Other languages have followed suit. E.g Rust's traits or Swift's protocol extensions. Design proposals are also on the table for Kotlin as [compile time dependency resolution](https://github.com/Kotlin/KEEP/blob/e863b25f8b3f2e9b9aaac361c6ee52be31453ee0/proposals/compile-time-dependency-resolution.md), for C# as [Shapes and Extensions](https://github.com/dotnet/csharplang/issues/164)
10+
Following Haskell, Scala was the second popular language to have some form of implicits. Other languages have followed suit. E.g [Rust's traits](https://doc.rust-lang.org/rust-by-example/trait.html) or [Swift's protocol extensions](https://docs.swift.org/swift-book/LanguageGuide/Protocols.html#ID521). Design proposals are also on the table for Kotlin as [compile time dependency resolution](https://github.com/Kotlin/KEEP/blob/e863b25f8b3f2e9b9aaac361c6ee52be31453ee0/proposals/compile-time-dependency-resolution.md), for C# as [Shapes and Extensions](https://github.com/dotnet/csharplang/issues/164)
1111
or for F# as [Traits](https://github.com/MattWindsor91/visualfsharp/blob/hackathon-vs/examples/fsconcepts.md). Implicits are also a common feature of theorem provers such as Coq or [Agda](https://agda.readthedocs.io/en/latest/language/implicit-arguments.html).
1212

1313
Even though these designs use widely different terminology, they are all variants of the core idea of _term inference_. Given a type, the compiler synthesizes a "canonical" term that has that type. Scala embodies the idea in a purer form than most other languages: An implicit parameter directly leads to an inferred argument term that could also be written down explicitly. By contrast, type class based designs are less direct since they hide term inference behind some form of type classification and do not offer the option of writing the inferred quantities (typically, dictionaries) explicitly.

docs/docs/reference/contextual/relationship-implicits.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Given instances can be mapped to combinations of implicit objects, classes and i
3333

3434
```scala
3535
class listOrd[T](implicit ord: Ord[T]) extends Ord[List[T]] { ... }
36-
final implicit def listOrd[T](implicit ord: Ord[T]): listOrd[T] = new listOrd[T]
36+
final implicit def listOrd[T](implicit ord: Ord[T]): listOrd[T] =
37+
new listOrd[T]
3738
```
3839

3940
3. Alias givens map to implicit methods or implicit lazy vals. If an alias has neither type nor context parameters,
@@ -76,7 +77,7 @@ Tuples are treated as transparent, i.e. a type `F[(X, Y)]` would get the synthes
7677

7778
### Using Clauses
7879

79-
Using clauses correspond largely to Scala-2's implicit parameter clauses. E.g.
80+
Using clauses correspond largely to Scala 2's implicit parameter clauses. E.g.
8081

8182
```scala
8283
def max[T](x: T, y: T)(using ord: Ord[T]): T
@@ -112,7 +113,8 @@ will map to using clauses instead.
112113
Extension methods have no direct counterpart in Scala 2, but they can be simulated with implicit classes. For instance, the extension method
113114

114115
```scala
115-
extension (c: Circle) def circumference: Double = c.radius * math.Pi * 2
116+
extension (c: Circle)
117+
def circumference: Double = c.radius * math.Pi * 2
116118
```
117119

118120
could be simulated to some degree by
@@ -123,7 +125,7 @@ implicit class CircleDecorator(c: Circle) extends AnyVal {
123125
}
124126
```
125127

126-
Abstract extension methods in traits that are implemented in given instances have no direct counterpart in Scala-2. The only way to simulate these is to make implicit classes available through imports. The Simulacrum macro library can automate this process in some cases.
128+
Abstract extension methods in traits that are implemented in given instances have no direct counterpart in Scala 2. The only way to simulate these is to make implicit classes available through imports. The Simulacrum macro library can automate this process in some cases.
127129

128130
### Type Class Derivation
129131

@@ -197,7 +199,7 @@ given SymDecorator = symDecorator
197199

198200
## Implementation Status and Timeline
199201

200-
The Scala 3 implementation implements both Scala-2's implicits and the new abstractions. In fact, support for Scala-2's implicits is an essential part of the common language subset between 2.13/2.14 and Scala 3.
202+
The Scala 3 implementation implements both Scala 2's implicits and the new abstractions. In fact, support for Scala 2's implicits is an essential part of the common language subset between 2.13/2.14 and Scala 3.
201203
Migration to the new abstractions will be supported by making automatic rewritings available.
202204

203205
Depending on adoption patterns, old style implicits might start to be deprecated in a version following Scala 3.0.

docs/docs/reference/dropped-features/auto-apply.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: "Dropped: Auto-Application"
44
---
55

66
Previously an empty argument list `()` was implicitly inserted when
7-
calling a nullary method without arguments. E.g.
7+
calling a nullary method without arguments. Example:
88
```scala
99
def next(): T = ...
1010
next // is expanded to next()
@@ -69,7 +69,7 @@ class B extends A {
6969
def next: Int // overriding error: incompatible type
7070
}
7171
```
72-
Methods overriding Java or Scala-2 methods are again exempted from this
72+
Methods overriding Java or Scala 2 methods are again exempted from this
7373
requirement.
7474

7575
### Migrating code

docs/docs/reference/dropped-features/class-shadowing-spec.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: doc-page
33
title: "Dropped: Class Shadowing - More Details"
44
---
55

6-
Spec diff: in section [5.1.4 Overriding](https://www.scala-lang.org/files/archive/spec/2.12/05-classes-and-objects.html), add *M' must not be a class*.
6+
Spec diff: in section [5.1.4 Overriding](https://www.scala-lang.org/files/archive/spec/2.13/05-classes-and-objects.html#Overriding), add *M' must not be a class*.
77

88
> Why do we want to make this change to the language?
99
@@ -12,7 +12,7 @@ Class shadowing is irregular compared to other types of overrides. Indeed, inner
1212

1313
> How much existing code is going to be affected?
1414
15-
From all the code compiled so far with Dotty the only instance of this I could find is in the stdlib. Looking at [this commit](https://github.com/lampepfl/scala/commit/68f13bf39979b631ed211ec1751934306ceb5d6c#diff-7aa508b70e055b47c823764e3e5646b8) it seems like the usage of class shadowing was accidental.
15+
From all the code compiled so far with Scala 3 the only instance of this I could find is in the stdlib. Looking at [this commit](https://github.com/lampepfl/scala/commit/68f13bf39979b631ed211ec1751934306ceb5d6c#diff-7aa508b70e055b47c823764e3e5646b8) it seems like the usage of class shadowing was accidental.
1616

1717

1818
> How exactly is existing code going to be affected?

docs/docs/reference/dropped-features/existential-types.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ layout: doc-page
33
title: "Dropped: Existential Types"
44
---
55

6-
Existential types using `forSome` have been dropped. The reasons for dropping them are:
6+
Existential types using `forSome` (as in
7+
[SLS §3.2.12](https://www.scala-lang.org/files/archive/spec/2.13/03-types.html#existential-types))
8+
have been dropped. The reasons for dropping them are:
79

810
- Existential types violate a type soundness principle on which DOT
911
and Scala 3 are constructed. That principle says that every
@@ -27,6 +29,6 @@ is treated as the type `Map`, where the first type parameter
2729
is upper-bounded by `AnyRef` and the second type parameter is an alias
2830
of `Int`.
2931

30-
When reading classfiles compiled with _scalac_, Scala 3 will do a best
32+
When reading class files compiled with Scala 2, Scala 3 will do a best
3133
effort to approximate existential types with its own types. It will
3234
issue a warning that a precise emulation is not possible.

docs/docs/reference/dropped-features/package-objects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package object p {
1212
```
1313
will be dropped. They are still available in Scala 3.0, but will be deprecated and removed afterwards.
1414

15-
Package objects are no longer needed since all kinds of definitions can now be written at the top-level. E.g.
15+
Package objects are no longer needed since all kinds of definitions can now be written at the top-level. Example:
1616
```scala
1717
package p
1818
type Labelled[T] = (String, T)

docs/docs/reference/dropped-features/procedure-syntax.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ has been dropped. You need to write one of the following instead:
1212
def f() = { ... }
1313
def f(): Unit = { ... }
1414
```
15-
Scala 3 will accept the old syntax under the `-source:3.0-migration` option.
15+
Scala 3 accepts the old syntax under the `-source:3.0-migration` option.
1616
If the `-migration` option is set, it can even rewrite old syntax to new.
1717
The [ScalaFix](https://scalacenter.github.io/scalafix/) tool also
18-
can rewrite procedure syntax to make it Scala-3-compatible.
18+
can rewrite procedure syntax to make it Scala 3 compatible.

0 commit comments

Comments
 (0)