Skip to content

Commit 3a7a6ae

Browse files
authored
Merge pull request #10767 from michelou/scala3-docs
[docs/reference] fixed many issues in MarkDown files
2 parents e8d748e + 6fbc7e5 commit 3a7a6ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+182
-162
lines changed

docs/docs/reference/changed-features/compiler-plugins.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class DivideZero extends StandardPlugin {
6666
val name: String = "divideZero"
6767
override val description: String = "divide zero check"
6868

69-
def init(options: List[String]): List[PluginPhase] = (new DivideZeroPhase) :: Nil
69+
def init(options: List[String]): List[PluginPhase] =
70+
(new DivideZeroPhase) :: Nil
7071
}
7172

7273
class DivideZeroPhase extends PluginPhase {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ where the type may still be inferred:
2424
...
2525
}
2626
```
27-
**2.** Nesting is now taken into account for selecting an implicit.Consider for instance the following scenario:
27+
**2.** Nesting is now taken into account for selecting an implicit. Consider for instance the following scenario:
2828
```scala
2929
def f(implicit i: C) = {
3030
def g(implicit j: C) = {
@@ -55,7 +55,7 @@ have only `b` in its implicit search scope but not `a`.
5555
In more detail, here are the rules for what constitutes the implicit scope of
5656
a type:
5757

58-
**Definition:** A reference is an _anchor_ if it refers to an object, a class, a trait, an abstract type, an opaque type alias, or a match type alias. References to packages and package objects are anchors only under -source:3.0-migration.
58+
**Definition:** A reference is an _anchor_ if it refers to an object, a class, a trait, an abstract type, an opaque type alias, or a match type alias. References to packages and package objects are anchors only under `-source:3.0-migration`.
5959

6060
**Definition:** The _anchors_ of a type _T_ is a set of references defined as follows:
6161

@@ -122,7 +122,7 @@ most (but not all) divergence errors in Scala 2 would terminate the implicit sea
122122
def buzz(y: A) = ???
123123
buzz(1) // error: ambiguous
124124
```
125-
**7.** The rule for picking a _most specific_ alternative among a set of overloaded or implicit alternatives is refined to take context parameters into account. All else being equal, an alternative that takes some context parameters is taken to be less specific than an alternative that takes none. If both alternatives take context parameters, we try to choose between them as if they were methods with regular parameters. The following paragraph in the SLS is affected by this change:
125+
**7.** The rule for picking a _most specific_ alternative among a set of overloaded or implicit alternatives is refined to take context parameters into account. All else being equal, an alternative that takes some context parameters is taken to be less specific than an alternative that takes none. If both alternatives take context parameters, we try to choose between them as if they were methods with regular parameters. The following paragraph in the [SLS §6.26.3](https://scala-lang.org/files/archive/spec/2.13/06-expressions.html#overloading-resolution) is affected by this change:
126126

127127
_Original version:_
128128

docs/docs/reference/changed-features/interpolation-escapes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: doc-page
33
title: Escapes in interpolations
44
---
55

6-
In Scala 2 there was no straightforward way to represent a single quote character `"` in a single quoted interpolation. A \ character can't be used for that because interpolators themselves decide how to handle escaping, so the parser doesn't know whether the " should be escaped or used as a terminator.
6+
In Scala 2 there was no straightforward way to represent a single quote character `"` in a single quoted interpolation. A `\` character can't be used for that because interpolators themselves decide how to handle escaping, so the parser doesn't know whether the `"` should be escaped or used as a terminator.
77

88
In Dotty, you can use the `$` meta character of interpolations to escape a `"` character.
99

docs/docs/reference/changed-features/match-syntax.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The syntactical precedence of match expressions has been changed.
1616
case "empty" => 0
1717
case "nonempty" => 1
1818
}
19+
```
1920

2021
2. `match` may follow a period:
2122

@@ -26,6 +27,7 @@ The syntactical precedence of match expressions has been changed.
2627
}
2728
then "nonempty"
2829
else "empty"
30+
```
2931

3032
3. The scrutinee of a match expression must be an `InfixExpr`. Previously the scrutinee could be followed by a type ascription `: T`, but this is no longer supported. So `x : T match { ... }` now has to be
3133
written `(x: T) match { ... }`.

docs/docs/reference/changed-features/numeric-literals.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ numbers that can have both a decimal point and an exponent:
7979
```scala
8080
object FromDigits {
8181

82-
/** A subclass of `FromDigits` that also allows to convert whole number literals
83-
* with a radix other than 10
82+
/** A subclass of `FromDigits` that also allows to convert whole
83+
* number literals with a radix other than 10
8484
*/
8585
trait WithRadix[T] extends FromDigits[T] {
8686
def fromDigits(digits: String): T = fromDigits(digits, 10)

docs/docs/reference/changed-features/operators.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ one of the following conditions holds:
4747
- the operator is followed by an opening brace.
4848

4949
An alphanumeric operator is an operator consisting entirely of letters, digits, the `$` and `_` characters, or
50-
any unicode character `c` for which `java.lang.Character.isIdentifierPart(c)` returns `true`.
50+
any Unicode character `c` for which `java.lang.Character.isIdentifierPart(c)` returns `true`.
5151

5252
Infix operations involving symbolic operators are always allowed, so `infix` is redundant for methods with symbolic names.
5353

@@ -89,9 +89,9 @@ The purpose of the `infix` modifier is to achieve consistency across a code base
8989
5. To smooth migration to Scala 3.0, alphanumeric operators will only be deprecated from Scala 3.1 onwards,
9090
or if the `-source 3.1` option is given in Dotty/Scala 3.
9191

92-
## The @targetName Annotation
92+
## The `@targetName` Annotation
9393

94-
It is recommended that definitions of symbolic operators carry a [@targetName annotation](../other-new-features/targetName.html) that provides an encoding of the operator with an alphanumeric name. This has several benefits:
94+
It is recommended that definitions of symbolic operators carry a [`@targetName` annotation](../other-new-features/targetName.md) that provides an encoding of the operator with an alphanumeric name. This has several benefits:
9595

9696
- It helps interoperability between Scala and other languages. One can call
9797
a Scala-defined symbolic operator from another language using its target name,
@@ -115,7 +115,7 @@ def condition =
115115
|| xs.exists(_ > 0)
116116
|| xs.isEmpty
117117
```
118-
Previously, these expressions would have been rejected, since the compiler's semicolon inference
118+
Previously, those expressions would have been rejected, since the compiler's semicolon inference
119119
would have treated the continuations `++ " world"` or `|| xs.isEmpty` as separate statements.
120120

121121
To make this syntax work, the rules are modified to not infer semicolons in front of leading infix operators.

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ are in the first argument list.
1313

1414
Overloading resolution now can take argument lists into account when
1515
choosing among a set of overloaded alternatives.
16-
For example, the following code compiles in Dotty, while it results in an
17-
ambiguous overload error in Scala2:
16+
For example, the following code compiles in Scala 3, while it results in an
17+
ambiguous overload error in Scala 2:
1818

1919
```scala
2020
def f(x: Int)(y: String): Int = 0
@@ -33,7 +33,7 @@ g(2)(3)(4) // ok
3333
g(2)(3)("") // ok
3434
```
3535

36-
To make this work, the rules for overloading resolution in section 6.23.3 of the SLS are augmented
36+
To make this work, the rules for overloading resolution in [SLS §6.26.3](https://www.scala-lang.org/files/archive/spec/2.13/06-expressions.html#overloading-resolution) are augmented
3737
as follows:
3838

3939
> In a situation where a function is applied to more than one argument list, if overloading
@@ -57,7 +57,7 @@ def f(x: String, f2: String => String) = f2(x)
5757
f("a", _.toUpperCase)
5858
f(2, _ * 2)
5959
```
60-
To make this work, the rules for overloading resolution in section 6.23.3 of the SLS are modified
60+
To make this work, the rules for overloading resolution in [SLS §6.26.3](https://www.scala-lang.org/files/archive/spec/2.13/06-expressions.html#overloading-resolution) are modified
6161
as follows:
6262

6363
Replace the sentence

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ want to decompose it like this:
2525
```scala
2626
val first :: rest = elems // error
2727
```
28-
This works in Scala 2. In fact it is a typical use case for Scala 2's rules. But in Scala 3.1 it will give a type error. One can avoid the error by marking the pattern with an @unchecked annotation:
28+
This works in Scala 2. In fact it is a typical use case for Scala 2's rules. But in Scala 3.1 it will give a type error. One can avoid the error by marking the pattern with an `@unchecked` annotation:
2929
```scala
3030
val first :: rest : @unchecked = elems // OK
3131
```
3232
This will make the compiler accept the pattern binding. It might give an error at runtime instead, if the underlying assumption that `elems` can never be empty is wrong.
3333

34-
## Pattern Bindings in For Expressions
34+
## Pattern Bindings in `for` Expressions
3535

3636
Analogous changes apply to patterns in `for` expressions. For instance:
3737

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ layout: doc-page
33
title: "Option-less pattern matching"
44
---
55

6-
Dotty implementation of pattern matching was greatly simplified compared to scalac. From a user perspective, this means that Dotty generated patterns are a *lot* easier to debug, as variables all show up in debug modes and positions are correctly preserved.
6+
Dotty implementation of pattern matching was greatly simplified compared to Scala 2. From a user perspective, this means that Scala 3 generated patterns are a *lot* easier to debug, as variables all show up in debug modes and positions are correctly preserved.
77

8-
Dotty supports a superset of scalac's [extractors](https://www.scala-lang.org/files/archive/spec/2.13/08-pattern-matching.html#extractor-patterns).
8+
Dotty supports a superset of Scala 2 [extractors](https://www.scala-lang.org/files/archive/spec/2.13/08-pattern-matching.html#extractor-patterns).
99

1010
## Extractors
1111

@@ -54,7 +54,7 @@ A usage of a fixed-arity extractor is irrefutable if one of the following condit
5454

5555
- `U = true`
5656
- the extractor is used as a product match
57-
- `U = Some[T]` (for Scala2 compatibility)
57+
- `U = Some[T]` (for Scala 2 compatibility)
5858
- `U <: R` and `U <: { def isEmpty: false }`
5959

6060
### Variadic Extractors
@@ -84,7 +84,7 @@ and `S` conforms to one of the two matches above.
8484
The former form of `unapplySeq` has higher priority, and _sequence match_ has higher
8585
precedence over _product-sequence match_.
8686

87-
A usage of a variadic extractor is irrefutable if one of the following condition holds:
87+
A usage of a variadic extractor is irrefutable if one of the following conditions holds:
8888

8989
- the extractor is used directly as a sequence match or product-sequence match
9090
- `U = Some[T]` (for Scala2 compatibility)
@@ -230,7 +230,8 @@ object CharList {
230230
```Scala
231231
class Foo(val name: String, val children: Int *)
232232
object Foo {
233-
def unapplySeq(f: Foo): Option[(String, Seq[Int])] = Some((f.name, f.children))
233+
def unapplySeq(f: Foo): Option[(String, Seq[Int])] =
234+
Some((f.name, f.children))
234235
}
235236

236237
def foo(f: Foo) = f match {

docs/docs/reference/changed-features/structural-types.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Here's an example of a structural type `Person`:
4242
val age: Int
4343
}
4444
```
45-
The person type adds a _refinement_ to its parent type `Record` that defines `name` and `age` fields. We say the refinement is _structural_ since `name` and `age` are not defined in the parent type. But they exist nevertheless as members of class `Person`. For instance, the following
45+
The type `Person` adds a _refinement_ to its parent type `Record` that defines the two fields `name` and `age`. We say the refinement is _structural_ since `name` and `age` are not defined in the parent type. But they exist nevertheless as members of class `Person`. For instance, the following
4646
program would print "Emma is 42 years old.":
4747
```scala
4848
val person = Record("name" -> "Emma", "age" -> 42).asInstanceOf[Person]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def position(s: String)(ch: Char, n: Int): Int =
267267
### Syntax
268268

269269
Here are the syntax changes for extension methods and collective extensions relative
270-
to the [current syntax](../../internals/syntax.md).
270+
to the [current syntax](../syntax.md).
271271

272272
```
273273
BlockStat ::= ... | Extension

docs/docs/reference/contextual/given-imports.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object B {
1818
}
1919
```
2020

21-
In the code above, the `import A._` clause of object `B` will import all members
21+
In the code above, the `import A._` clause in object `B` imports all members
2222
of `A` _except_ the given instance `tc`. Conversely, the second import `import A.given` will import _only_ that given instance.
2323
The two import clauses can also be merged into one:
2424

@@ -67,7 +67,7 @@ object Instances {
6767
}
6868
```
6969

70-
the import
70+
the import clause
7171

7272
```scala
7373
import Instances.{given Ordering[?], given ExecutionContext}

docs/docs/reference/contextual/givens.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: "Given Instances"
44
---
55

66
Given instances (or, simply, "givens") define "canonical" values of certain types
7-
that serve for synthesizing arguments to [context parameters](./using-clauses.html). Example:
7+
that serve for synthesizing arguments to [context parameters](./using-clauses.md). Example:
88

99
```scala
1010
trait Ord[T] {
@@ -34,7 +34,7 @@ for `Ord[List[T]]` for all types `T` that come with a given instance for `Ord[T]
3434
themselves. The `using` clause in `listOrd` defines a condition: There must be a
3535
given of type `Ord[T]` for a given of type `Ord[List[T]]` to exist.
3636
Such conditions are expanded by the compiler to [context
37-
parameters](./using-clauses.html).
37+
parameters](./using-clauses.md).
3838

3939
## Anonymous Givens
4040

@@ -108,7 +108,7 @@ In each case, a pattern-bound given instance consists of `given` and a type `T`.
108108

109109
## Negated Givens
110110

111-
Scala 2's somewhat puzzling behavior with respect to ambiguity has been exploited to implement the analogue of a "negated" search in implicit resolution, where a query Q1 fails if some other query Q2 succeeds and Q1 succeeds if Q2 fails. With the new cleaned up behavior these techniques no longer work. But there is now a new special type `scala.util.NotGiven` which implements negation directly.
111+
Scala 2's somewhat puzzling behavior with respect to ambiguity has been exploited to implement the analogue of a "negated" search in implicit resolution, where a query Q1 fails if some other query Q2 succeeds and Q1 succeeds if Q2 fails. With the new cleaned up behavior these techniques no longer work. But the new special type `scala.util.NotGiven` now implements negation directly.
112112

113113
For any query type `Q`, `NotGiven[Q]` succeeds if and only if the implicit
114114
search for `Q` fails, for example:

docs/docs/reference/contextual/motivation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ title: "Overview"
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

1010
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)
11-
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.
11+
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.
1414

docs/docs/reference/contextual/type-classes.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ assertTransformation(List("a1", "b1"), List("a", "b"), elt => s"${elt}1")
9797
```
9898

9999
That's a first step, but in practice we probably would like the `map` function to be a method directly accessible on the type `F`. So that we can call `map` directly on instances of `F`, and get rid of the `summon[Functor[F]]` part.
100-
As in the previous example of Monoids, [`extension` methods](extension-methods.html) help achieving that. Let's re-define the `Functor` type class with extension methods.
100+
As in the previous example of Monoids, [`extension` methods](extension-methods.md) help achieving that. Let's re-define the `Functor` type class with extension methods.
101101

102102
```scala
103103
trait Functor[F[_]]:
@@ -234,7 +234,7 @@ given configDependentMonad: Monad[ConfigDependent] with
234234
end configDependentMonad
235235
```
236236

237-
The type `ConfigDependent` can be written using [type lambdas](../new-types/type-lambdas.html):
237+
The type `ConfigDependent` can be written using [type lambdas](../new-types/type-lambdas.md):
238238

239239
```scala
240240
type ConfigDependent = [Result] =>> Config => Result

0 commit comments

Comments
 (0)