Skip to content

Commit bbfff61

Browse files
Merge pull request #11158 from michelou/scala3-docs
more fixes in Markdown files
2 parents b2edd43 + 73e3ea1 commit bbfff61

File tree

10 files changed

+72
-38
lines changed

10 files changed

+72
-38
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pluginClass=dividezero.DivideZero
4242
This is different from `scalac` plugins that required a `scalac-plugin.xml` file.
4343

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

4747
## Writing a Standard Compiler Plugin
4848

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
layout: doc-page
3-
title: Escapes in interpolations
3+
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 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.
77

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

1010
```scala
1111
val inventor = "Thomas Edison"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The Scala compiler generates a program from a `@main` method `f` as follows:
5656
- The class has a static method `main` with the usual signature. It takes an `Array[String]`
5757
as argument and returns `Unit`.
5858
- The generated `main` method calls method `f` with arguments converted using
59-
methods in the [`scala.util.CommandLineParser` object](https://dotty.epfl.ch/api/scala/util/CommandLineParser$.html).
59+
methods in the [`scala.util.CommandLineParser`](https://dotty.epfl.ch/api/scala/util/CommandLineParser$.html) object.
6060

6161
For instance, the `happyBirthDay` method above would generate additional code equivalent to the following class:
6262

@@ -84,5 +84,5 @@ object happyBirthday extends App:
8484
...
8585
```
8686

87-
The previous functionality of `App`, which relied on the "magic" [`DelayedInit`](../dropped-features/delayed-init.md) trait, is no longer available. `App` 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
87+
The previous functionality of `App`, which relied on the "magic" [`DelayedInit`](../dropped-features/delayed-init.md) trait, is no longer available. [`App`](https://dotty.epfl.ch/api/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
8888
between Scala 2 and Scala 3, it is recommended to use an explicit `main` method with an `Array[String]` argument instead.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: doc-page
3-
title: How to write a type class `derived` method using macros
3+
title: "How to write a type class `derived` method using macros"
44
---
55

66
In the main [derivation](./derivation.md) documentation page, we explained the
@@ -97,8 +97,8 @@ One additional difference with the body of `derived` here as opposed to the one
9797
with `inline` is that with macros we need to synthesize the body of the code during the
9898
macro-expansion time. That is the rationale behind the `eqProductBody` function.
9999
Assuming that we calculate the equality of two `Person`s defined with a case
100-
class that holds a name of type `String` and an age of type `Int`, the equality
101-
check we want to generate is the following:
100+
class that holds a name of type [`String`](https://dotty.epfl.ch/api/scala/Predef$.html#String)
101+
and an age of type `Int`, the equality check we want to generate is the following:
102102

103103
```scala
104104
true

docs/docs/reference/dropped-features/early-initializers.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ title: "Dropped: Early Initializers"
44
---
55

66
Early initializers of the form
7+
78
```scala
89
class C extends { ... } with SuperClass ...
910
```
11+
1012
have been dropped. They were rarely used, and mostly to compensate for the lack of
1113
[trait parameters](../other-new-features/trait-parameters.md), which are now directly supported in Scala 3.
14+
15+
For more information, see [SLS §5.1.6](https://www.scala-lang.org/files/archive/spec/2.13/05-classes-and-objects.html#early-definitions).

docs/docs/reference/metaprogramming/macros.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ schemes with the familiar string interpolation syntax.
1616
println(s"Hello, $name, here is the result of 1 + 1 = ${1 + 1}")
1717
```
1818

19-
In string interpolation we _quoted_ a string and then we _spliced_ into it, two
20-
others. The first, `name`, is a reference to a value of type `string`, and the
21-
second is an arithmetic expression that will be _evaluated_ followed by the
22-
splicing of its string representation.
19+
In string interpolation we _quoted_ a string and then we _spliced_ into it, two others. The first, `name`, is a reference to a value of type [`String`](https://dotty.epfl.ch/api/scala/Predef$.html#String), and the second is an arithmetic expression that will be _evaluated_ followed by the splicing of its string representation.
2320

2421
Quotes and splices in this section allow us to treat code in a similar way,
2522
effectively supporting macros. The entry point for macros is an inline method
@@ -86,7 +83,7 @@ and it takes types `T` to expressions of type `Type[T]`. Splicing
8683
takes expressions of type `Expr[T]` to expressions of type `T` and it
8784
takes expressions of type `Type[T]` to types `T`.
8885

89-
The two types can be defined in package `scala.quoted` as follows:
86+
The two types can be defined in package [`scala.quoted`](https://dotty.epfl.ch/api/scala/quoted.html) as follows:
9087

9188
```scala
9289
package scala.quoted

docs/docs/reference/metaprogramming/tasty-inspect.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ import scala.quoted._
2222
import scala.tasty.inspector._
2323

2424
class MyInspector extends TastyInspector:
25-
protected def processCompilationUnit(using Quotes)(tree: quotes.reflect.Tree): Unit =
26-
import quotes.reflect._
27-
// Do something with the tree
25+
protected def processCompilationUnit(using Quotes)(tree: quotes.reflect.Tree): Unit =
26+
import quotes.reflect._
27+
// Do something with the tree
2828
```
2929

3030
Then the consumer can be instantiated with the following code to get the tree of the `foo/Bar.tasty` file.
3131

3232
```scala
3333
object Test:
34-
def main(args: Array[String]): Unit =
35-
new MyInspector().inspectTastyFiles("foo/Bar.tasty")
34+
def main(args: Array[String]): Unit =
35+
new MyInspector().inspectTastyFiles("foo/Bar.tasty")
3636
```
3737

3838
Note that if we need to run the main (in the example below defined in an object called `Test`) after compilation we need to make the compiler available to the runtime:

docs/docs/reference/other-new-features/safe-initialization.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ field points to an initialized object may not later point to an
141141
object under initialization. As an example, the following code will be rejected:
142142

143143
``` scala
144-
trait Reporter { def report(msg: String): Unit }
144+
trait Reporter:
145+
def report(msg: String): Unit
146+
145147
class FileReporter(ctx: Context) extends Reporter:
146148
ctx.typer.reporter = this // ctx now reaches an uninitialized object
147149
val file: File = new File("report.txt")

docs/docs/reference/other-new-features/type-test.md

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ f[AnyRef, String]("acb")(using tt)
6969
```
7070

7171
The compiler will synthesize a new instance of a type test if none is found in scope as:
72+
7273
```scala
7374
new TypeTest[A, B]:
7475
def unapply(s: A): Option[s.type & B] = s match
7576
case s: B => Some(s)
7677
case _ => None
7778
```
79+
7880
If the type tests cannot be done there will be an unchecked warning that will be raised on the `case s: B =>` test.
7981

8082
The most common `TypeTest` instances are the ones that take any parameters (i.e. `TypeTest[Any, T]`).
@@ -106,11 +108,13 @@ Using `ClassTag` instances was unsound since classtags can check only the class
106108
`ClassTag` type tests are still supported but a warning will be emitted after 3.0.
107109

108110

109-
## Examples
111+
## Example
110112

111-
Given the following abstract definition of `Peano` numbers that provides `TypeTest[Nat, Zero]` and `TypeTest[Nat, Succ]`
113+
Given the following abstract definition of Peano numbers that provides two given instances of types `TypeTest[Nat, Zero]` and `TypeTest[Nat, Succ]`
112114

113115
```scala
116+
import scala.reflect._
117+
114118
trait Peano:
115119
type Nat
116120
type Zero <: Nat
@@ -125,25 +129,52 @@ trait Peano:
125129
def apply(nat: Nat): Succ
126130
def unapply(nat: Succ): Option[Nat]
127131

128-
given TypeTest[Nat, Zero] = typeTestOfZero
129-
protected def typeTestOfZero: TypeTest[Nat, Zero]
130-
given TypeTest[Nat, Succ] = typeTestOfSucc
131-
protected def typeTestOfSucc: TypeTest[Nat, Succ]
132+
given typeTestOfZero: TypeTest[Nat, Zero]
133+
given typeTestOfSucc: TypeTest[Nat, Succ]
132134
```
133135

134-
it will be possible to write the following program
136+
together with an implementation of Peano numbers based on type `Int`
135137

136138
```scala
137-
val peano: Peano = ...
138-
import peano._
139-
def divOpt(m: Nat, n: Nat): Option[(Nat, Nat)] =
140-
n match
141-
case Zero => None
142-
case s @ Succ(_) => Some(safeDiv(m, s))
143-
144-
val two = Succ(Succ(Zero))
145-
val five = Succ(Succ(Succ(two)))
146-
println(divOpt(five, two))
139+
object PeanoInt extends Peano:
140+
type Nat = Int
141+
type Zero = Int
142+
type Succ = Int
143+
144+
def safeDiv(m: Nat, n: Succ): (Nat, Nat) = (m / n, m % n)
145+
146+
val Zero: Zero = 0
147+
148+
val Succ: SuccExtractor = new:
149+
def apply(nat: Nat): Succ = nat + 1
150+
def unapply(nat: Succ) = Some(nat - 1)
151+
152+
def typeTestOfZero: TypeTest[Nat, Zero] = new:
153+
def unapply(x: Nat): Option[x.type & Zero] =
154+
if x == 0 then Some(x) else None
155+
156+
def typeTestOfSucc: TypeTest[Nat, Succ] = new:
157+
def unapply(x: Nat): Option[x.type & Succ] =
158+
if x > 0 then Some(x) else None
159+
```
160+
161+
it is possible to write the following program
162+
163+
```scala
164+
@main def test =
165+
import PeanoInt._
166+
167+
def divOpt(m: Nat, n: Nat): Option[(Nat, Nat)] =
168+
n match
169+
case Zero => None
170+
case s @ Succ(_) => Some(safeDiv(m, s))
171+
172+
val two = Succ(Succ(Zero))
173+
val five = Succ(Succ(Succ(two)))
174+
175+
println(divOpt(five, two)) // prints "Some((2,1))"
176+
println(divOpt(two, five)) // prints "Some((0,2))"
177+
println(divOpt(two, Zero)) // prints "None"
147178
```
148179

149180
Note that without the `TypeTest[Nat, Succ]` the pattern `Succ.unapply(nat: Succ)` would be unchecked.

docs/docs/reference/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ These constructs replace existing constructs with the aim of making the language
4848
instead of `new` expressions. `new` expressions stay around as a fallback for
4949
the cases where creator applications cannot be used.
5050

51-
With the exception of early initializers and old-style vararg patterns, all superseded constructs continue to be available in Scala 3.0. The plan is to deprecate and phase them out later.
51+
With the exception of [early initializers](dropped-features/early-initializers.md) and old-style vararg patterns, all superseded constructs continue to be available in Scala 3.0. The plan is to deprecate and phase them out later.
5252

5353
Value classes (superseded by opaque type aliases) are a special case. There are currently no deprecation plans for value classes, since we might bring them back in a more general form if they are supported natively by the JVM as is planned by [project Valhalla](https://openjdk.java.net/projects/valhalla/).
5454

0 commit comments

Comments
 (0)