Skip to content

Commit a1cb3df

Browse files
committed
Add small improvements to the Reference page
1 parent a6a3385 commit a1cb3df

22 files changed

+53
-78
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ title: "Changes in Compiler Plugins"
44
nightlyOf: https://docs.scala-lang.org/scala3/reference/changed-features/compiler-plugins.html
55
---
66

7-
Compiler plugins are supported by Dotty (and Scala 3) since 0.9. There are two notable changes
8-
compared to `scalac`:
7+
Compiler plugins are supported in Scala 3 since Dotty 0.9. There are two notable changes
8+
compared to Scala 2:
99

1010
- No support for analyzer plugins
1111
- Added support for research plugins
1212

13-
[Analyzer plugins][1] in `scalac` run during type checking and may influence
13+
[Analyzer plugins][1] run in Scala 2 during type checking and may influence
1414
normal type checking. This is a very powerful feature but for production usages,
1515
a predictable and consistent type checker is more important.
1616

1717
For experimentation and research, Scala 3 introduces _research plugin_. Research plugins
18-
are more powerful than `scalac` analyzer plugins as they let plugin authors customize
18+
are more powerful than Scala 2 analyzer plugins as they let plugin authors customize
1919
the whole compiler pipeline. One can easily replace the standard typer by a custom one or
2020
create a parser for a domain-specific language. However, research plugins are only
2121
enabled for nightly or snaphot releases of Scala 3.
@@ -26,7 +26,7 @@ _standard plugins_ in Scala 3. In terms of features, they are similar to
2626

2727
## Using Compiler Plugins
2828

29-
Both standard and research plugins can be used with `scalac` by adding the `-Xplugin:` option:
29+
In Scala 3, both standard and research plugins can be used with `scalac` by adding the `-Xplugin:` option:
3030

3131
```shell
3232
scalac -Xplugin:pluginA.jar -Xplugin:pluginB.jar Test.scala
@@ -40,7 +40,7 @@ the fully qualified plugin class name. The format of a property file is as follo
4040
pluginClass=dividezero.DivideZero
4141
```
4242

43-
This is different from `scalac` plugins that required a `scalac-plugin.xml` file.
43+
This is different from Scala 2 plugins that require a `scalac-plugin.xml` file.
4444

4545
Starting from 1.1.5, `sbt` also supports Scala 3 compiler plugins. Please refer to the
4646
[`sbt` documentation][2] for more information.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ implicit val bla: Double = 1.0
5151
val bar = foo // val bar: Int => Float = ...
5252
```
5353

54-
## Automatic Eta-Expansion and query types
54+
## Automatic Eta-Expansion and context types
5555

5656
A method with context parameters can be expanded to a value of a context type by writing the expected context type explicitly.
5757

@@ -66,7 +66,7 @@ val bar: Double ?=> Float = foo(3)
6666
- If `m` is has an empty argument list (i.e. has type `()R`):
6767
1. If the expected type is of the form `() => T`, we eta expand.
6868
2. If m is defined by Java, or overrides a Java defined method, we insert `()`.
69-
3. Otherwise we issue an error of the form:
69+
3. Otherwise we issue an error of the form: `method must be called with () argument`
7070

7171
Thus, an unapplied method with an empty argument list is only converted to a function when a function type is expected. It is considered best practice to either explicitly apply the method to `()`, or convert it to a function with `() => m()`.
7272

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ final class happyBirthday:
7272
case error: CLP.ParseError => CLP.showError(error)
7373
```
7474

75-
**Note**: The `<static>` modifier above expresses that the `main` method is generated
75+
**Note:** The `<static>` modifier above expresses that the `main` method is generated
7676
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.
7777

7878
[`@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:

docs/_docs/reference/contextual/by-name-context-parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ In the example above, the definition of `s` would be expanded as follows.
5353

5454
```scala
5555
val s = summon[Test.Codec[Option[Int]]](
56-
optionCodec[Int](using intCodec)
56+
using optionCodec[Int](using intCodec)
5757
)
5858
```
5959

docs/_docs/reference/contextual/givens.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ that serve for synthesizing arguments to [context parameters](./using-clauses.md
1010
```scala
1111
trait Ord[T]:
1212
def compare(x: T, y: T): Int
13-
extension (x: T) def < (y: T) = compare(x, y) < 0
14-
extension (x: T) def > (y: T) = compare(x, y) > 0
13+
extension (x: T)
14+
def < (y: T) = compare(x, y) < 0
15+
def > (y: T) = compare(x, y) > 0
1516

1617
given intOrd: Ord[Int] with
1718
def compare(x: Int, y: Int) =
@@ -51,7 +52,7 @@ given [T](using Ord[T]): Ord[List[T]] with
5152
If the name of a given is missing, the compiler will synthesize a name from
5253
the implemented type(s).
5354

54-
**Note** The name synthesized by the compiler is chosen to be readable and reasonably concise. For instance, the two instances above would get the names:
55+
**Note:** The name synthesized by the compiler is chosen to be readable and reasonably concise. For instance, the two instances above would get the names:
5556

5657
```scala
5758
given_Ord_Int
@@ -62,7 +63,7 @@ The precise rules for synthesizing names are found [here](./relationship-implici
6263
given instances of types that are "too similar". To avoid conflicts one can
6364
use named instances.
6465

65-
**Note** To ensure robust binary compatibility, publicly available libraries should prefer named instances.
66+
**Note:** To ensure robust binary compatibility, publicly available libraries should prefer named instances.
6667

6768
## Alias Givens
6869

docs/_docs/reference/contextual/multiversal-equality.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ that derives `CanEqual`, e.g.
3333
```scala
3434
class T derives CanEqual
3535
```
36+
> Normally a [derives clause](./derivation.md) accepts only type classes with one parameter, however there is a special case for `CanEqual`.
3637
3738
Alternatively, one can also provide a `CanEqual` given instance directly, like this:
3839

@@ -82,7 +83,7 @@ def canEqualAny[L, R]: CanEqual[L, R] = CanEqual.derived
8283
```
8384

8485
Even though `canEqualAny` is not declared as `given`, the compiler will still
85-
construct an `canEqualAny` instance as answer to an implicit search for the
86+
construct a `canEqualAny` instance as answer to an implicit search for the
8687
type `CanEqual[L, R]`, unless `L` or `R` have `CanEqual` instances
8788
defined on them, or the language feature `strictEquality` is enabled.
8889

@@ -156,10 +157,10 @@ Instances are defined so that every one of these types has a _reflexive_ `CanEqu
156157
- Primitive numeric types can be compared with subtypes of `java.lang.Number` (and _vice versa_).
157158
- `Boolean` can be compared with `java.lang.Boolean` (and _vice versa_).
158159
- `Char` can be compared with `java.lang.Character` (and _vice versa_).
159-
- Two sequences (of arbitrary subtypes of `scala.collection.Seq`) can be compared
160+
- Two sequences (arbitrary subtypes of `scala.collection.Seq`) can be compared
160161
with each other if their element types can be compared. The two sequence types
161162
need not be the same.
162-
- Two sets (of arbitrary subtypes of `scala.collection.Set`) can be compared
163+
- Two sets (arbitrary subtypes of `scala.collection.Set`) can be compared
163164
with each other if their element types can be compared. The two set types
164165
need not be the same.
165166
- Any subtype of `AnyRef` can be compared with `Null` (and _vice versa_).

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ given Functor[List] with
8282
x.map(f) // List already has a `map` method
8383
```
8484

85-
With this `given` instance in scope, everywhere a `Functor` is expected, the compiler will accept a `List` to be used.
85+
With this `given` instance in scope, everywhere a type with a `Functor` context bound is expected, the compiler will accept a `List` to be used.
8686

8787
For instance, we may write such a testing method:
8888

@@ -214,7 +214,7 @@ instead of
214214
show(compute(i)(config))(config)
215215
```
216216

217-
Let's define this m then. First, we are going to define a type named `ConfigDependent` representing a function that when passed a `Config` produces a `Result`.
217+
Let's define this `flatMap` then. First, we are going to define a type named `ConfigDependent` representing a function that when passed a `Config` produces a `Result`.
218218

219219
```scala
220220
type ConfigDependent[Result] = Config => Result

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object HelloWorld extends App {
1818
```
1919

2020
However, the code is now run in the initializer of the object, which on
21-
some JVM's means that it will only be interpreted. So, better not use it
21+
some JVMs means that it will only be interpreted. So, better not use it
2222
for benchmarking! Also, if you want to access the command line arguments,
2323
you need to use an explicit `main` method for that.
2424

docs/_docs/reference/experimental/canthrow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ try
124124
body
125125
catch ...
126126
```
127-
Note that the right-hand side of the synthesized given is `???` (undefined). This is OK since
127+
Note that the right-hand side of the synthesized given is `compiletime.erasedValue`. This is OK since
128128
this given is erased; it will not be executed at runtime.
129129

130130
**Note 1:** The [`saferExceptions`](https://scala-lang.org/api/3.x/scala/runtime/stdLibPatches/language$$experimental$$saferExceptions$.html) feature is designed to work only with checked exceptions. An exception type is _checked_ if it is a subtype of

docs/_docs/reference/experimental/cc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def f(x: {c}-> Int): Int
176176
```
177177
Here, the actual argument to `f` is allowed to use the `c` capability but no others.
178178

179-
**Note**: It is strongly recommended to write the capability set and the arrow `->` without intervening spaces,
179+
**Note:** It is strongly recommended to write the capability set and the arrow `->` without intervening spaces,
180180
as otherwise the notation would look confusingly like a function type.
181181

182182
## Subtyping and Subcapturing

docs/_docs/reference/experimental/explicit-nulls.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,4 +540,4 @@ Our strategy for binary compatibility with Scala binaries that predate explicit
540540
and new libraries compiled without `-Yexplicit-nulls` is to leave the types unchanged
541541
and be compatible but unsound.
542542

543-
[More details](https://dotty.epfl.ch/docs/internals/explicit-nulls.html)
543+
[Implementation details](https://dotty.epfl.ch/docs/internals/explicit-nulls.html)

docs/_docs/reference/experimental/numeric-literals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: "Numeric Literals"
44
nightlyOf: https://docs.scala-lang.org/scala3/reference/experimental/numeric-literals.html
55
---
66

7-
**Note**: This feature is not yet part of the Scala 3 language definition. It can be made available by a language import:
7+
This feature is not yet part of the Scala 3 language definition. It can be made available by a language import:
88

99
```scala
1010
import scala.language.experimental.genericNumberLiterals

docs/_docs/reference/language-versions/source-compatibility.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ class C { ... }
4040

4141
Language imports supersede command-line settings in the source files where they are specified. Only one language import specifying a source version is allowed in a source file, and it must come before any definitions in that file.
4242

43-
**Note**: The [Scala 3 Migration Guide](https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html) gives further information to help the Scala programmer moving from Scala 2.13 to Scala 3.
43+
**Note:** The [Scala 3 Migration Guide](https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html) gives further information to help the Scala programmer moving from Scala 2.13 to Scala 3.

docs/_docs/reference/metaprogramming/compiletime-ops.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The [`scala.compiletime`](https://scala-lang.org/api/3.x/scala/compiletime.html)
1111
### `constValue` and `constValueOpt`
1212

1313
`constValue` is a function that produces the constant value represented by a
14-
type.
14+
type, or a compile time error if the type is not a constant type.
1515

1616
```scala
1717
import scala.compiletime.constValue
@@ -30,6 +30,8 @@ enabling us to handle situations where a value is not present. Note that `S` is
3030
the type of the successor of some singleton type. For example the type `S[1]` is
3131
the singleton type `2`.
3232

33+
Since tuples are not constant types, even if their constituants are, there is `constValueTuple`, which given a tuple type `(X1, ..., Xn)`, returns a tuple value `(constValue[X1], ..., constValue[Xn])`.
34+
3335
### `erasedValue`
3436

3537
So far we have seen inline methods that take terms (tuples and integers) as
@@ -170,24 +172,24 @@ val concat: "a" + "b" = "ab"
170172
val addition: 1 + 1 = 2
171173
```
172174

173-
## Summoning Implicits Selectively
175+
## Summoning Givens Selectively
174176

175177
It is foreseen that many areas of typelevel programming can be done with rewrite
176178
methods instead of implicits. But sometimes implicits are unavoidable. The
177179
problem so far was that the Prolog-like programming style of implicit search
178180
becomes viral: Once some construct depends on implicit search it has to be
179181
written as a logic program itself. Consider for instance the problem of creating
180182
a `TreeSet[T]` or a `HashSet[T]` depending on whether `T` has an `Ordering` or
181-
not. We can create a set of implicit definitions like this:
183+
not. We can create a set of given instances like this:
182184

183185
```scala
184186
trait SetFor[T, S <: Set[T]]
185187

186188
class LowPriority:
187-
implicit def hashSetFor[T]: SetFor[T, HashSet[T]] = ...
189+
given hashSetFor[T]: SetFor[T, HashSet[T]] = ...
188190

189191
object SetsFor extends LowPriority:
190-
implicit def treeSetFor[T: Ordering]: SetFor[T, TreeSet[T]] = ...
192+
given treeSetFor[T: Ordering]: SetFor[T, TreeSet[T]] = ...
191193
```
192194

193195
Clearly, this is not pretty. Besides all the usual indirection of implicit
@@ -236,18 +238,18 @@ inline def setFor[T]: Set[T] = summonFrom {
236238

237239
`summonFrom` applications must be reduced at compile time.
238240

239-
Consequently, if we summon an `Ordering[String]` the code above will return a
240-
new instance of `TreeSet[String]`.
241+
Consequently, if a given instance of `Ordering[String]` is in the implicit scope, the code above will return a
242+
new instance of `TreeSet[String]`. Such an instance is defined in `Ordering`'s companion object, so there will always be one.
241243

242244
```scala
243-
summon[Ordering[String]]
245+
summon[Ordering[String]] // Proves that an Ordering[String] is in scope
244246

245247
println(setFor[String].getClass) // prints class scala.collection.immutable.TreeSet
246248
```
247249

248-
**Note** `summonFrom` applications can raise ambiguity errors. Consider the following
250+
**Note:** `summonFrom` applications can raise ambiguity errors. Consider the following
249251
code with two givens in scope of type `A`. The pattern match in `f` will raise
250-
an ambiguity error of `f` is applied.
252+
an ambiguity error if `f` is applied.
251253

252254
```scala
253255
class A

docs/_docs/reference/metaprogramming/metaprogramming.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ introduce the following fundamental facilities:
3939
representation of code. They can be parameterized and composed using
4040
splices, but their structure cannot be analyzed from the outside. TASTy
4141
reflection gives a way to analyze code structure by partly revealing the representation type of a piece of code in a standard API. The representation
42-
type is a form of typed abstract syntax tree, which gives rise to the `TASTy`
42+
type is a form of **t**yped **a**bstract **s**yntax **t**ree, which gives rise to the `TASTy`
4343
moniker.
4444

4545
6. [TASTy Inspection](./tasty-inspect.md) Typed abstract syntax trees are serialized

docs/_docs/reference/new-types/type-lambdas-spec.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ type O2[X] = List[X]
103103
```
104104
would be treated as covariant, `X` is used covariantly on its right-hand side.
105105

106-
**Note**: The decision to treat `Nothing` as universal bottom type is provisional, and might be changed after further discussion.
106+
**Note:** The decision to treat `Nothing` as universal bottom type is provisional, and might be changed after further discussion.
107107

108-
**Note**: Scala 2 and 3 differ in that Scala 2 also treats `Any` as universal top-type. This is not done in Scala 3. See also the discussion on [kind polymorphism](../other-new-features/kind-polymorphism.md)
108+
**Note:** Scala 2 and 3 differ in that Scala 2 also treats `Any` as universal top-type. This is not done in Scala 3. See also the discussion on [kind polymorphism](../other-new-features/kind-polymorphism.md)
109109

110110
## Curried Type Parameters
111111

docs/_docs/reference/other-new-features/export.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,16 @@ Consider the following example:
201201

202202
```scala
203203
class B { val c: Int }
204-
object a { val b = new B }
205-
export a.*
204+
object A { val b = new B }
205+
export A.*
206206
export b.*
207207
```
208208

209-
Is the `export b.*` clause legal? If yes, what does it export? Is it equivalent to `export a.b.*`? What about if we swap the last two clauses?
209+
Is the `export b.*` clause legal? If yes, what does it export? Is it equivalent to `export A.b.*`? What about if we swap the last two clauses?
210210

211211
```
212212
export b.*
213-
export a.*
213+
export A.*
214214
```
215215

216216
To avoid tricky questions like these, we fix the elaboration order of exports as follows.

docs/_docs/reference/other-new-features/kind-polymorphism.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ It is declared `abstract` and `final`, so it can be neither instantiated nor ext
4343

4444
`AnyKind` plays a special role in Scala's subtype system: It is a supertype of all other types no matter what their kind is. It is also assumed to be kind-compatible with all other types. Furthermore, `AnyKind` is treated as a higher-kinded type (so it cannot be used as a type of values), but at the same time it has no type parameters (so it cannot be instantiated).
4545

46-
**Note**: This feature is considered experimental but stable and it can be disabled under compiler flag
46+
**Note:** This feature is considered experimental but stable and it can be disabled under compiler flag
4747
(i.e. `-Yno-kind-polymorphism`).

docs/_docs/reference/other-new-features/opaques-details.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ opaque type G = [T] =>> List[T]
6565
but the following are not:
6666
```scala
6767
opaque type BadF[T] = [U] =>> (T, U)
68-
opaque type BadG = [T] =>> [U] => (T, U)
68+
opaque type BadG = [T] =>> [U] =>> (T, U)
6969
```
7070

7171
## Translation of Equality

docs/_docs/reference/other-new-features/parameter-untupling-spec.md

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,7 @@ title: "Parameter Untupling - More Details"
44
nightlyOf: https://docs.scala-lang.org/scala3/reference/other-new-features/parameter-untupling-spec.html
55
---
66

7-
## Motivation
87

9-
Say you have a list of pairs
10-
11-
```scala
12-
val xs: List[(Int, Int)]
13-
```
14-
15-
and you want to map `xs` to a list of `Int`s so that each pair of numbers is mapped to their sum.
16-
Previously, the best way to do this was with a pattern-matching decomposition:
17-
18-
```scala
19-
xs.map {
20-
case (x, y) => x + y
21-
}
22-
```
23-
While correct, this is inconvenient. Instead, we propose to write it the following way:
24-
25-
```scala
26-
xs.map {
27-
(x, y) => x + y
28-
}
29-
```
30-
31-
or, equivalently:
32-
33-
```scala
34-
xs.map(_ + _)
35-
```
36-
37-
Generally, a function value with `n > 1` parameters can be converted to a function with tupled arguments if the expected type is a unary function type of the form `((T_1, ..., T_n)) => U`.
388

399
## Type Checking
4010

docs/_docs/reference/other-new-features/parameter-untupling.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ The function value must be explicitly tupled, rather than the parameters untuple
5757
xs.map(combiner.tupled)
5858
```
5959

60-
A conversion may be provided in user code:
60+
Though strongly discouraged, to have the same effect, an implicit conversion may be provided in user code:
6161

6262
```scala
6363
import scala.language.implicitConversions
64-
transparent inline implicit def `fallback untupling`(f: (Int, Int) => Int): ((Int, Int)) => Int =
65-
p => f(p._1, p._2) // use specialized apply instead of unspecialized `tupled`
64+
65+
transparent inline given `fallback untupling`: Conversion[(Int, Int) => Int, ((Int, Int)) => Int] = _.tupled
66+
6667
xs.map(combiner)
6768
```
6869

docs/_docs/reference/other-new-features/targetName.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The relevant overriding rules can be summarized as follows:
9393
- If two members override, then both their erased names and their types must be the same.
9494

9595
As usual, any overriding relationship in the generated code must also
96-
be present in the original code. So the following example would also be in error:
96+
be present in the original code. So the following example would also be an error:
9797

9898
```scala
9999
import annotation.targetName

0 commit comments

Comments
 (0)