Skip to content

Commit c9c6de6

Browse files
Merge pull request #14191 from michelou/scala3-docs
more updates to Markdown files
2 parents 04946d2 + 7ea9083 commit c9c6de6

33 files changed

+431
-416
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defined by either:
1212
- An `implicit def` which has type `S => T` or `(=> S) => T`
1313
- An implicit value which has type `Conversion[S, T]`
1414

15-
The standard library defines an abstract class `Conversion`:
15+
The standard library defines an abstract class [`Conversion`](https://scala-lang.org/api/3.x/scala/Conversion.html):
1616

1717
```scala
1818
package scala
@@ -86,7 +86,7 @@ Note that implicit conversions are also affected by the [changes to implicit res
8686

8787
## Motivation for the changes
8888

89-
The introduction of [`scala.Conversion`](https://github.com/lampepfl/dotty/blob/master/library/src/scala/Conversion.scala)
89+
The introduction of [`scala.Conversion`](https://scala-lang.org/api/3.x/scala/Conversion.html)
9090
in Scala 3 and the decision to restrict implicit values of this type to be
9191
considered as potential views comes from the desire to remove surprising
9292
behavior from the language:
@@ -102,7 +102,7 @@ This snippet contains a type error. The right-hand side of `val x`
102102
does not conform to type `String`. In Scala 2, the compiler will use
103103
`m` as an implicit conversion from `Int` to `String`, whereas Scala 3
104104
will report a type error, because `Map` isn't an instance of
105-
`Conversion`.
105+
[`Conversion`](https://scala-lang.org/api/3.x/scala/Conversion.html).
106106

107107
## Migration path
108108

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ Defining an implicit conversion will emit a warning unless the import
2828

2929
## Examples
3030

31-
The first example is taken from `scala.Predef`. Thanks to this
32-
implicit conversion, it is possible to pass a `scala.Int` to a Java
33-
method that expects a `java.lang.Integer`
31+
The first example is taken from [`scala.Predef`](https://scala-lang.org/api/3.x/scala/Predef$.html).
32+
Thanks to this implicit conversion, it is possible to pass a
33+
[`scala.Int`](https://scala-lang.org/api/3.x/scala/Int.html)
34+
to a Java method that expects a `java.lang.Integer`
3435

3536
```scala
3637
import scala.language.implicitConversions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ which means that the alternative `c` would be chosen as solution!
110110
Scala 2's somewhat puzzling behavior with respect to ambiguity has been exploited to implement
111111
the analogue of a "negated" search in implicit resolution, where a query `Q1` fails if some
112112
other query `Q2` succeeds and `Q1` succeeds if `Q2` fails. With the new cleaned up behavior
113-
these techniques no longer work. But there is now a new special type `scala.util.NotGiven`
113+
these techniques no longer work. But there is now a new special type [`scala.util.NotGiven`](https://scala-lang.org/api/3.x/scala/util/NotGiven.html)
114114
which implements negation directly. For any query type `Q`, `NotGiven[Q]` succeeds if and only if
115115
the implicit search for `Q` fails.
116116

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: "Escapes in interpolations"
44
movedTo: https://docs.scala-lang.org/scala3/reference/changed-features/interpolation-escapes.html
55
---
66

7-
In Scala 2 there is 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.
7+
In Scala 2 there is 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 `"` character should be escaped or used as a terminator.
88

99
In Scala 3, we can use the `$` meta character of interpolations to escape a `"` character. Example:
1010

docs/docs/reference/changed-features/main-functions.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ movedTo: https://docs.scala-lang.org/scala3/reference/changed-features/main-func
55
---
66

77
Scala 3 offers a new way to define programs that can be invoked from the command line:
8-
A `@main` annotation on a method turns this method into an executable program.
8+
A [`@main`](https://scala-lang.org/api/3.x/scala/main.html) annotation on a method turns this method into an executable program.
99
Example:
1010

1111
```scala
@@ -31,13 +31,11 @@ This would generate a main program `happyBirthday` that could be called like thi
3131
Happy 23rd birthday, Lisa and Peter
3232
```
3333

34-
A `@main` annotated method can be written either at the top-level or in a statically accessible object. The name of the program is in each case the name of the method, without any object prefixes. The `@main` method can have an arbitrary number of parameters.
35-
For each parameter type there must be an instance of the `scala.util.CommandLineParser.FromString` type class
36-
that is used to convert an argument string to the required parameter type.
37-
The parameter list of a main method can end in a repeated parameter that then
38-
takes all remaining arguments given on the command line.
34+
A [`@main`](https://scala-lang.org/api/3.x/scala/main.html) annotated method can be written either at the top-level or in a statically accessible object. The name of the program is in each case the name of the method, without any object prefixes. The [`@main`](https://scala-lang.org/api/3.x/scala/main.html) method can have an arbitrary number of parameters.
35+
For each parameter type there must be an instance of the [`scala.util.CommandLineParser.FromString[T]`](https://scala-lang.org/api/3.x/scala/util/CommandLineParser$$FromString.html) type class that is used to convert an argument string to the required parameter type `T`.
36+
The parameter list of a main method can end in a repeated parameter that then takes all remaining arguments given on the command line.
3937

40-
The program implemented from a `@main` method checks that there are enough arguments on
38+
The program implemented from a [`@main`](https://scala-lang.org/api/3.x/scala/main.html) method checks that there are enough arguments on
4139
the command line to fill in all parameters, and that argument strings are convertible to
4240
the required types. If a check fails, the program is terminated with an error message.
4341

@@ -51,11 +49,11 @@ Illegal command line after first argument: more arguments expected
5149
Illegal command line: java.lang.NumberFormatException: For input string: "sixty"
5250
```
5351

54-
The Scala compiler generates a program from a `@main` method `f` as follows:
52+
The Scala compiler generates a program from a [`@main`](https://scala-lang.org/api/3.x/scala/main.html) method `f` as follows:
5553

56-
- It creates a class named `f` in the package where the `@main` method was found
54+
- It creates a class named `f` in the package where the [`@main`](https://scala-lang.org/api/3.x/scala/main.html) method was found
5755
- The class has a static method `main` with the usual signature. It takes an `Array[String]`
58-
as argument and returns `Unit`.
56+
as argument and returns [`Unit`](https://scala-lang.org/api/3.x/scala/Unit.html).
5957
- The generated `main` method calls method `f` with arguments converted using
6058
methods in the [`scala.util.CommandLineParser`](https://scala-lang.org/api/3.x/scala/util/CommandLineParser$.html) object.
6159

@@ -77,13 +75,13 @@ final class happyBirthday:
7775
**Note**: The `<static>` modifier above expresses that the `main` method is generated
7876
as a static method of class `happyBirthDay`. It is not available for user programs in Scala. Regular "static" members are generated in Scala using objects instead.
7977

80-
`@main` methods are the recommended scheme to generate programs that can be invoked from the command line in Scala 3. They replace the previous scheme to write program as objects with a special `App` parent class. In Scala 2, `happyBirthday` could be written also like this:
78+
[`@main`](https://scala-lang.org/api/3.x/scala/main.html) methods are the recommended scheme to generate programs that can be invoked from the command line in Scala 3. They replace the previous scheme to write program as objects with a special `App` parent class. In Scala 2, `happyBirthday` could be written also like this:
8179

8280
```scala
8381
object happyBirthday extends App:
8482
// needs by-hand parsing of arguments vector
8583
...
8684
```
8785

88-
The previous functionality of `App`, which relied on the "magic" [`DelayedInit`](../dropped-features/delayed-init.md) trait, is no longer available. [`App`](https://scala-lang.org/api/3.x/scala/App.md) still exists in limited form for now, but it does not support command line arguments and will be deprecated in the future. If programs need to cross-build
86+
The previous functionality of [`App`](https://www.scala-lang.org/api/3.x/scala/App.html), which relied on the "magic" [`DelayedInit`](../dropped-features/delayed-init.md) trait, is no longer available. [`App`](https://scala-lang.org/api/3.x/scala/App.html) still exists in limited form for now, but it does not support command line arguments and will be deprecated in the future. If programs need to cross-build
8987
between Scala 2 and Scala 3, it is recommended to use an explicit `main` method with an `Array[String]` argument instead.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ This code gives a compile-time warning in Scala 3.1 (and also in Scala 3.0 under
2121
val pair = (1, true)
2222
val (x, y) = pair
2323
```
24-
Sometimes one wants to decompose data anyway, even though the pattern is refutable. For instance, if at some point one knows that a list `elems` is non-empty one might
25-
want to decompose it like this:
24+
Sometimes one wants to decompose data anyway, even though the pattern is refutable. For instance, if at some point one knows that a list `elems` is non-empty one might want to decompose it like this:
2625
```scala
2726
val first :: rest = elems // error
2827
```
29-
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 warning. One can avoid the warning by marking the right-hand side 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 warning. One can avoid the warning by marking the right-hand side with an [`@unchecked`](https://scala-lang.org/api/3.x/scala/unchecked.html) annotation:
3029
```scala
3130
val first :: rest = elems: @unchecked // OK
3231
```

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ help from the user. In practice, the connection between a structural type
5959
and its underlying generic representation would most likely be done by
6060
a database layer, and therefore would not be a concern of the end user.
6161

62-
`Record` extends the marker trait `scala.Selectable` and defines
62+
`Record` extends the marker trait [`scala.Selectable`](https://scala-lang.org/api/3.x/scala/Selectable.html) and defines
6363
a method `selectDynamic`, which maps a field name to its value.
6464
Selecting a structural type member is done by calling this method.
6565
The `person.name` and `person.age` selections are translated by
@@ -90,7 +90,7 @@ Structural types can also be accessed using [Java reflection](https://www.oracle
9090
def close(): Unit
9191
```
9292

93-
Here, we define a structural type `Closeable` that defines a `close` method. There are various classes that have `close` methods, we just list `FileInputStream` and `Channel` as two examples. It would be easiest if the two classes shared a common interface that factors out the `close` method. But such factorings are often not possible if different libraries are combined in one application. Yet, we can still have methods that work on
93+
Here, we define a structural type `Closeable` that defines a `close` method. There are various classes that have `close` methods, we just list [`FileInputStream`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/FileInputStream.html#%3Cinit%3E(java.io.File)) and [`Channel`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/channels/Channel.html) as two examples. It would be easiest if the two classes shared a common interface that factors out the `close` method. But such factorings are often not possible if different libraries are combined in one application. Yet, we can still have methods that work on
9494
all classes with a `close` method by using the `Closeable` type. For instance,
9595

9696
```scala
@@ -147,10 +147,9 @@ i3.range
147147

148148
The type of `i3` in this example is `Vehicle { val range: Int }`. Hence,
149149
`i3.range` is well-formed. Since the base class `Vehicle` does not define a `range` field or method, we need structural dispatch to access the `range` field of the anonymous class that initializes `id3`. Structural dispatch
150-
is implemented by the base trait `reflect.Selectable` of `Vehicle`, which
151-
defines the necessary `selectDynamic` member.
150+
is implemented by the base trait [`reflect.Selectable`](https://scala-lang.org/api/3.x/scala/reflect/Selectable.html) of `Vehicle`, which defines the necessary `selectDynamic` member.
152151

153-
`Vehicle` could also extend some other subclass of `scala.Selectable` that implements `selectDynamic` and `applyDynamic` differently. But if it does not extend a `Selectable` at all, the code would no longer typecheck:
152+
`Vehicle` could also extend some other subclass of [`scala.Selectable`](https://scala-lang.org/api/3.x/scala/Selectable.html) that implements `selectDynamic` and `applyDynamic` differently. But if it does not extend a `Selectable` at all, the code would no longer typecheck:
154153

155154
```scala
156155
trait Vehicle:
@@ -168,25 +167,25 @@ adding any refinements. Hence, `i3` now has just type `Vehicle` and the selectio
168167

169168
Note that in Scala 2 all local and anonymous classes could produce values with refined types. But
170169
members defined by such refinements could be selected only with the language import
171-
`reflectiveCalls`.
170+
[`reflectiveCalls`](https://scala-lang.org/api/3.x/scala/languageFeature$$reflectiveCalls$.html).
172171

173172
## Relation with `scala.Dynamic`
174173

175-
There are clearly some connections with `scala.Dynamic` here, since
174+
There are clearly some connections with [`scala.Dynamic`](https://scala-lang.org/api/3.x/scala/Dynamic.html) here, since
176175
both select members programmatically. But there are also some
177176
differences.
178177

179178
- Fully dynamic selection is not typesafe, but structural selection
180179
is, as long as the correspondence of the structural type with the
181180
underlying value is as stated.
182181

183-
- `Dynamic` is just a marker trait, which gives more leeway where and
182+
- [`Dynamic`](https://scala-lang.org/api/3.x/scala/Dynamic.html) is just a marker trait, which gives more leeway where and
184183
how to define reflective access operations. By contrast
185184
`Selectable` is a trait which declares the access operations.
186185

187186
- Two access operations, `selectDynamic` and `applyDynamic` are shared
188187
between both approaches. In `Selectable`, `applyDynamic` also may also take
189-
`java.lang.Class` arguments indicating the method's formal parameter types.
190-
`Dynamic` comes with `updateDynamic`.
188+
[`java.lang.Class`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Class.html) arguments indicating the method's formal parameter types.
189+
[`Dynamic`](https://scala-lang.org/api/3.x/scala/Dynamic.html) comes with `updateDynamic`.
191190

192191
[More details](structural-types-spec.md)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
layout: doc-page
33
title: "Context Functions - More Details"
4-
54
movedTo: https://docs.scala-lang.org/scala3/reference/contextual/context-functions-spec.html
65
---
76

@@ -64,7 +63,7 @@ Context function literals `(x1: T1, ..., xn: Tn) ?=> e` are
6463
automatically created for any expression `e` whose expected type is
6564
`scala.ContextFunctionN[T1, ..., Tn, R]`, unless `e` is
6665
itself a context function literal. This is analogous to the automatic
67-
insertion of `scala.Function0` around expressions in by-name argument position.
66+
insertion of [`scala.Function0`](https://scala-lang.org/api/3.x/scala/Function0.html) around expressions in by-name argument position.
6867

6968
Context function types generalize to `N > 22` in the same way that function types do, see [the corresponding
7069
documentation](../dropped-features/limit22.md).

docs/docs/reference/contextual/givens.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ In each case, a pattern-bound given instance consists of `given` and a type `T`.
120120

121121
Scala 2's somewhat puzzling behavior with respect to ambiguity has been exploited to implement the analogue of a "negated" search in implicit resolution,
122122
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.
123-
But the new special type `scala.util.NotGiven` now implements negation directly.
123+
But the new special type [`scala.util.NotGiven`](https://scala-lang.org/api/3.x/scala/util/NotGiven.html) now implements negation directly.
124124

125-
For any query type `Q`, `NotGiven[Q]` succeeds if and only if the implicit
125+
For any query type `Q`, [`NotGiven[Q]`](https://scala-lang.org/api/3.x/scala/util/NotGiven.html) succeeds if and only if the implicit
126126
search for `Q` fails, for example:
127127

128128
```scala

docs/docs/reference/dropped-features/delayed-init.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ title: "Dropped: DelayedInit"
44
movedTo: https://docs.scala-lang.org/scala3/reference/dropped-features/delayed-init.html
55
---
66

7-
The special handling of the `DelayedInit` trait is no longer supported.
7+
The special handling of the [`DelayedInit`](https://scala-lang.org/api/3.x/scala/DelayedInit.html)
8+
trait is no longer supported.
89

9-
One consequence is that the `App` class, which used `DelayedInit` is
10+
One consequence is that the [`App`](https://scala-lang.org/api/3.x/scala/App.html) class,
11+
which used [`DelayedInit`](https://scala-lang.org/api/3.x/scala/DelayedInit.html) is
1012
now partially broken. You can still use `App` as a simple way to set up a main program. Example:
1113

1214
```scala

0 commit comments

Comments
 (0)