Skip to content

Commit 626d24a

Browse files
authored
Merge pull request #10875 from michelou/scala3-docs
[docs/reference] more fixes in Markdown files
2 parents 842919a + 5d5a066 commit 626d24a

34 files changed

+128
-113
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ val x: String = 1 // Scala 2: assigns "abc" to x
102102
This snippet contains a type error. The right hand side of `val x`
103103
does not conform to type `String`. In Scala 2, the compiler will use
104104
`m` as an implicit conversion from `Int` to `String`, whereas Scala 3
105-
will report a type error, because Map isn't an instance of
105+
will report a type error, because `Map` isn't an instance of
106106
`Conversion`.
107107

108108
## Migration path

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: doc-page
3-
title: Rules for Operators
3+
title: "Rules for Operators"
44
---
55

66
The rules for infix operators have changed in some parts:

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The standard library defines a universal marker trait `Selectable` in the packag
2020
trait Selectable extends Any
2121
```
2222

23-
An implementation of `Selectable` that relies on Java reflection is
23+
An implementation of `Selectable` that relies on [Java reflection](https://www.oracle.com/technical-resources/articles/java/javareflection.html) is
2424
available in the standard library: `scala.reflect.Selectable`. Other
2525
implementations can be envisioned for platforms where Java reflection
2626
is not available.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Besides `selectDynamic`, a `Selectable` class sometimes also defines a method `a
7171

7272
## Using Java Reflection
7373

74-
Structural types can also be accessed using Java reflection. Example:
74+
Structural types can also be accessed using [Java reflection](https://www.oracle.com/technical-resources/articles/java/javareflection.html). Example:
7575
```scala
7676
type Closeable = { def close(): Unit }
7777

docs/docs/reference/changed-features/vararg-patterns.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The change to the grammar is:
3535

3636
## Compatibility considerations
3737

38-
To enable smooth cross compilation between Scala 2 and Scala 3, Dotty will
38+
To enable smooth cross compilation between Scala 2 and Scala 3, the compiler will
3939
accept both the old and the new syntax. Under the `-source 3.1` setting, an error
4040
will be emitted when the old syntax is encountered. They will be enabled by
4141
default in version 3.1 of the language.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ check we want to generate is the following:
106106
&& Eq[Int].eqv(x.productElement(1), y.productElement(1))
107107
```
108108

109-
### Calling the derived method inside the macro
109+
## Calling the derived method inside the macro
110110

111111
Following the rules in [Macros](../metaprogramming/toc.md) we create two methods.
112112
One that hosts the top-level splice `eqv` and one that is the implementation.

docs/docs/reference/contextual/derivation.md

+17-14
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ sealed trait Mirror:
5959

6060
object Mirror:
6161

62-
/** The Mirror for a product type */
63-
trait Product extends Mirror:
62+
/** The Mirror for a product type */
63+
trait Product extends Mirror:
6464

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

7070
trait Sum extends Mirror:
7171

@@ -125,12 +125,12 @@ Note the following properties of `Mirror` types,
125125
+ The kinds of `MirroredType` and `MirroredElemTypes` match the kind of the data type the mirror is an instance for.
126126
This allows `Mirrors` to support ADTs of all kinds.
127127
+ There is no distinct representation type for sums or products (ie. there is no `HList` or `Coproduct` type as in
128-
Scala 2 versions of shapeless). Instead the collection of child types of a data type is represented by an ordinary,
128+
Scala 2 versions of Shapeless). Instead the collection of child types of a data type is represented by an ordinary,
129129
possibly parameterized, tuple type. Scala 3's metaprogramming facilities can be used to work with these tuple types
130130
as-is, and higher level libraries can be built on top of them.
131131
+ For both product and sum types, the elements of `MirroredElemTypes` are arranged in definition order (i.e. `Branch[T]`
132132
precedes `Leaf[T]` in `MirroredElemTypes` for `Tree` because `Branch` is defined before `Leaf` in the source file).
133-
This means that `Mirror.Sum` differs in this respect from shapeless's generic representation for ADTs in Scala 2,
133+
This means that `Mirror.Sum` differs in this respect from Shapeless's generic representation for ADTs in Scala 2,
134134
where the constructors are ordered alphabetically by name.
135135
+ The methods `ordinal` and `fromProduct` are defined in terms of `MirroredMonoType` which is the type of kind-`*`
136136
which is obtained from `MirroredType` by wildcarding its type parameters.
@@ -159,7 +159,7 @@ Type class authors will most likely use higher level derivation or generic progr
159159
described above and Scala 3's general metaprogramming features is provided below. It is not anticipated that type class
160160
authors would normally implement a `derived` method in this way, however this walkthrough can be taken as a guide for
161161
authors of the higher level derivation libraries that we expect typical type class authors will use (for a fully
162-
worked out example of such a library, see [shapeless 3](https://github.com/milessabin/shapeless/tree/shapeless-3)).
162+
worked out example of such a library, see [Shapeless 3](https://github.com/milessabin/shapeless/tree/shapeless-3)).
163163

164164
#### How to write a type class `derived` method using low level mechanisms
165165

@@ -307,7 +307,7 @@ Alternative approaches can be taken to the way that `derived` methods can be def
307307
inlined variants using Scala 3 macros, whilst being more involved for type class authors to write than the example
308308
above, can produce code for type classes like `Eq` which eliminate all the abstraction artefacts (eg. the `Lists` of
309309
child instances in the above) and generate code which is indistinguishable from what a programmer might write by hand.
310-
As a third example, using a higher level library such as shapeless the type class author could define an equivalent
310+
As a third example, using a higher level library such as Shapeless the type class author could define an equivalent
311311
`derived` method as,
312312

313313
```scala
@@ -317,9 +317,12 @@ given eqSum[A](using inst: => K0.CoproductInstances[Eq, A]): Eq[A] with
317317

318318
given eqProduct[A](using inst: K0.ProductInstances[Eq, A]): Eq[A] with
319319
def eqv(x: A, y: A): Boolean = inst.foldLeft2(x, y)(true: Boolean)(
320-
[t] => (acc: Boolean, eqt: Eq[t], t0: t, t1: t) => Complete(!eqt.eqv(t0, t1))(false)(true)
320+
[t] => (acc: Boolean, eqt: Eq[t], t0: t, t1: t) =>
321+
Complete(!eqt.eqv(t0, t1))(false)(true)
322+
)
321323

322-
inline def derived[A](using gen: K0.Generic[A]) as Eq[A] = gen.derive(eqSum, eqProduct)
324+
inline def derived[A](using gen: K0.Generic[A]) as Eq[A] =
325+
gen.derive(eqSum, eqProduct)
323326
```
324327

325328
The framework described here enables all three of these approaches without mandating any of them.
@@ -385,6 +388,6 @@ written these casts will never fail.
385388
As mentioned, however, the compiler-provided mechanism is intentionally very low level and it is anticipated that
386389
higher level type class derivation and generic programming libraries will build on this and Scala 3's other
387390
metaprogramming facilities to hide these low-level details from type class authors and general users. Type class
388-
derivation in the style of both shapeless and Magnolia are possible (a prototype of shapeless 3, which combines
389-
aspects of both shapeless 2 and Magnolia has been developed alongside this language feature) as is a more aggressively
391+
derivation in the style of both Shapeless and Magnolia are possible (a prototype of Shapeless 3, which combines
392+
aspects of both Shapeless 2 and Magnolia has been developed alongside this language feature) as is a more aggressively
390393
inlined style, supported by Scala 3's new quote/splice macro and inlining facilities.

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

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import Instances.{im, given Ordering[?]}
8080
```
8181

8282
would import `im`, `intOrd`, and `listOrd` but leave out `ec`.
83+
8384
### Migration
8485

8586
The rules for imports stated above have the consequence that a library

docs/docs/reference/contextual/motivation.md

+5-3
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](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)
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).
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](https://coq.inria.fr/refman/language/extensions/implicit-arguments.html) 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

@@ -30,12 +30,14 @@ Particular criticisms are:
3030
3. The syntax of implicit definitions is too minimal. It consists of a single modifier, `implicit`, that can be attached to a large number of language constructs. A problem with this for newcomers is that it conveys mechanism instead of intent. For instance, a type class instance is an implicit object or val if unconditional and an implicit def with implicit parameters referring to some class if conditional. This describes precisely what the implicit definitions translate to -- just drop the `implicit` modifier, and that's it! But the cues that define intent are rather indirect and can be easily misread, as demonstrated by the definitions of `i1` and `i2` above.
3131

3232
4. The syntax of implicit parameters also has shortcomings. While implicit _parameters_ are designated specifically, arguments are not. Passing an argument to an implicit parameter looks like a regular application `f(arg)`. This is problematic because it means there can be confusion regarding what parameter gets instantiated in a call. For instance, in
33+
3334
```scala
3435
def currentMap(implicit ctx: Context): Map[String, Int]
3536
```
36-
one cannot write `currentMap("abc")` since the string "abc" is taken as explicit argument to the implicit `ctx` parameter. One has to write `currentMap.apply("abc")` instead, which is awkward and irregular. For the same reason, a method definition can only have one implicit parameter section and it must always come last. This restriction not only reduces orthogonality, but also prevents some useful program constructs, such as a method with a regular parameter whose type depends on an implicit value. Finally, it's also a bit annoying that implicit parameters must have a name, even though in many cases that name is never referenced.
3737

38-
5. Implicits pose challenges for tooling. The set of available implicits depends on context, so command completion has to take context into account. This is feasible in an IDE but docs like ScalaDoc that are based static web pages can only provide an approximation. Another problem is that failed implicit searches often give very unspecific error messages, in particular if some deeply recursive implicit search has failed. Note that the Scala 3 compiler has already made a lot of progress in the error diagnostics area. If a recursive search fails some levels down, it shows what was constructed and what is missing. Also, it suggests imports that can bring missing implicits in scope.
38+
one cannot write `currentMap("abc")` since the string `"abc"` is taken as explicit argument to the implicit `ctx` parameter. One has to write `currentMap.apply("abc")` instead, which is awkward and irregular. For the same reason, a method definition can only have one implicit parameter section and it must always come last. This restriction not only reduces orthogonality, but also prevents some useful program constructs, such as a method with a regular parameter whose type depends on an implicit value. Finally, it's also a bit annoying that implicit parameters must have a name, even though in many cases that name is never referenced.
39+
40+
5. Implicits pose challenges for tooling. The set of available implicits depends on context, so command completion has to take context into account. This is feasible in an IDE but tools like [Scaladoc](https://docs.scala-lang.org/overviews/scaladoc/overview.html) that are based on static web pages can only provide an approximation. Another problem is that failed implicit searches often give very unspecific error messages, in particular if some deeply recursive implicit search has failed. Note that the Scala 3 compiler has already made a lot of progress in the error diagnostics area. If a recursive search fails some levels down, it shows what was constructed and what is missing. Also, it suggests imports that can bring missing implicits in scope.
3941

4042
None of the shortcomings is fatal, after all implicits are very widely used, and many libraries and applications rely on them. But together, they make code using implicits a lot more cumbersome and less clear than it could be.
4143

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ class Box[T](x: T) derives CanEqual
9696
By the usual rules of [type class derivation](./derivation.md),
9797
this generates the following `CanEqual` instance in the companion object of `Box`:
9898
```scala
99-
given [T, U](using CanEqual[T, U]): CanEqual[Box[T], Box[U]] = CanEqual.derived
99+
given [T, U](using CanEqual[T, U]): CanEqual[Box[T], Box[U]] =
100+
CanEqual.derived
100101
```
101102
That is, two boxes are comparable with `==` or `!=` if their elements are. Examples:
102103
```scala

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ mirroring the definition syntax. E.g, `max(2, 3)(using IntOrd)`.
9595
Scala 2 uses normal applications `max(2, 3)(IntOrd)` instead. The Scala 2 syntax has some inherent ambiguities and restrictions which are overcome by the new syntax. For instance, multiple implicit parameter lists are not available in the old syntax, even though they can be simulated using auxiliary objects in the "Aux" pattern.
9696

9797
The `summon` method corresponds to `implicitly` in Scala 2.
98-
It is precisely the same as the `the` method in Shapeless.
98+
It is precisely the same as the `the` method in [Shapeless](https://github.com/milessabin/shapeless).
9999
The difference between `summon` (or `the`) and `implicitly` is
100100
that `summon` can return a more precise type than the type that was
101101
asked for.
@@ -129,7 +129,7 @@ Abstract extension methods in traits that are implemented in given instances hav
129129

130130
### Type Class Derivation
131131

132-
Type class derivation has no direct counterpart in the Scala 2 language. Comparable functionality can be achieved by macro-based libraries such as Shapeless, Magnolia, or scalaz-deriving.
132+
Type class derivation has no direct counterpart in the Scala 2 language. Comparable functionality can be achieved by macro-based libraries such as [Shapeless](https://github.com/milessabin/shapeless), [Magnolia](https://propensive.com/opensource/magnolia), or [scalaz-deriving](https://github.com/scalaz/scalaz-deriving).
133133

134134
### Context Function Types
135135

docs/docs/reference/enums/desugarEnums.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ some terminology and notational conventions:
2525

2626
The desugaring rules imply that class cases are mapped to case classes, and singleton cases are mapped to `val` definitions.
2727

28-
There are nine desugaring rules. Rule (1) desugar enum definitions. Rules
28+
There are nine desugaring rules. Rule (1) desugars enum definitions. Rules
2929
(2) and (3) desugar simple cases. Rules (4) to (6) define `extends` clauses for cases that
3030
are missing them. Rules (7) to (9) define how such cases with `extends` clauses
3131
map into `case class`es or `val`s.
@@ -176,10 +176,11 @@ If `E` contains at least one simple case, its companion object will define in ad
176176
follows.
177177

178178
```scala
179-
private def $new(_$ordinal: Int, $name: String) = new E with runtime.EnumValue:
180-
def ordinal = _$ordinal
181-
override def productPrefix = $name // if not overridden in `E`
182-
override def toString = $name // if not overridden in `E`
179+
private def $new(_$ordinal: Int, $name: String) =
180+
new E with runtime.EnumValue:
181+
def ordinal = _$ordinal
182+
override def productPrefix = $name // if not overridden in `E`
183+
override def toString = $name // if not overridden in `E`
183184
```
184185

185186
The anonymous class also implements the abstract `Product` methods that it inherits from `Enum`.

docs/docs/reference/enums/enums.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The companion object of an enum also defines three utility methods.
4444
The `valueOf` method obtains an enum value
4545
by its name. The `values` method returns all enum values
4646
defined in an enumeration in an `Array`. The `fromOrdinal`
47-
method obtains an enum value from its ordinal (Int) value.
47+
method obtains an enum value from its ordinal (`Int`) value.
4848

4949
```scala
5050
scala> Color.valueOf("Blue")
@@ -63,7 +63,7 @@ It is possible to add your own definitions to an enum. Example:
6363
enum Planet(mass: Double, radius: Double):
6464
private final val G = 6.67300E-11
6565
def surfaceGravity = G * mass / (radius * radius)
66-
def surfaceWeight(otherMass: Double) = otherMass * surfaceGravity
66+
def surfaceWeight(otherMass: Double) = otherMass * surfaceGravity
6767

6868
case Mercury extends Planet(3.303e+23, 2.4397e6)
6969
case Venus extends Planet(4.869e+24, 6.0518e6)
@@ -72,7 +72,7 @@ enum Planet(mass: Double, radius: Double):
7272
case Jupiter extends Planet(1.9e+27, 7.1492e7)
7373
case Saturn extends Planet(5.688e+26, 6.0268e7)
7474
case Uranus extends Planet(8.686e+25, 2.5559e7)
75-
case Neptune extends Planet(1.024e+26, 2.4746e7)
75+
case Neptune extends Planet(1.024e+26, 2.4746e7)
7676
end Planet
7777
```
7878

docs/docs/reference/features-classification.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Being new features, existing code migrates without changes. To be sure, sometime
162162

163163
## Metaprogramming
164164

165-
The following constructs together aim to put metaprogramming in Scala on a new basis. So far, metaprogramming was achieved by a combination of macros and libraries such as Shapeless that were in turn based on some key macros. Current Scala 2 macro mechanisms are a thin veneer on top the current Scala 2 compiler, which makes them fragile and in many cases impossible to port to Scala 3.
165+
The following constructs together aim to put metaprogramming in Scala on a new basis. So far, metaprogramming was achieved by a combination of macros and libraries such as [Shapeless](https://github.com/milessabin/shapeless) that were in turn based on some key macros. Current Scala 2 macro mechanisms are a thin veneer on top the current Scala 2 compiler, which makes them fragile and in many cases impossible to port to Scala 3.
166166

167167
It's worth noting that macros were never included in the Scala 2 language specification and were so far made available only under an `-experimental` flag. This has not prevented their widespread usage.
168168

docs/docs/reference/metaprogramming/erased-terms-spec.md

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ layout: doc-page
33
title: "Erased Terms Spec"
44
---
55

6-
# Implementation
7-
86
## Rules
97

108
1. The `erased` modifier can appear:

0 commit comments

Comments
 (0)