You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/reference/changed-features/main-functions.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: "Main Methods"
4
4
---
5
5
6
6
Scala 3 offers a new way to define programs that can be invoked from the command line:
7
-
A `@main`{.scala} annotation on a method turns this method into an executable program.
7
+
A `@main` annotation on a method turns this method into an executable program.
8
8
Example:
9
9
10
10
```scala
@@ -30,13 +30,13 @@ This would generate a main program `happyBirthday` that could be called like thi
30
30
Happy 23rd Birthday, Lisa and Peter!
31
31
```
32
32
33
-
A `@main`{.scala} 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`{.scala} method can have an arbitrary number of parameters.
33
+
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.
34
34
For each parameter type there must be an instance of the `scala.util.FromString` type class
35
35
that is used to convert an argument string to the required parameter type.
36
36
The parameter list of a main method can end in a repeated parameter that then
37
37
takes all remaining arguments given on the command line.
38
38
39
-
The program implemented from a `@main`{.scala} method checks that there are enough arguments on
39
+
The program implemented from a `@main` method checks that there are enough arguments on
40
40
the command line to fill in all parameters, and that argument strings are convertible to
41
41
the required types. If a check fails, the program is terminated with an error message.
42
42
@@ -50,9 +50,9 @@ Illegal command line after first argument: more arguments expected
50
50
Illegal command line: java.lang.NumberFormatException: For input string: "sixty"
51
51
```
52
52
53
-
The Scala compiler generates a program from a `@main`{.scala} method `f` as follows:
53
+
The Scala compiler generates a program from a `@main` method `f` as follows:
54
54
55
-
- It creates a class named `f` in the package where the `@main`{.scala} method was found
55
+
- It creates a class named `f` in the package where the `@main` method was found
56
56
- The class has a static method `main` with the usual signature. It takes an `Array[String]`
57
57
as argument and returns `Unit`.
58
58
- The generated `main` method calls method `f` with arguments converted using
@@ -76,7 +76,7 @@ final class happyBirthday:
76
76
**Note**: The `<static>` modifier above expresses that the `main` method is generated
77
77
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.
78
78
79
-
`@main`{.scala} 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:
79
+
`@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:
Copy file name to clipboardExpand all lines: docs/docs/reference/changed-features/operators.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@ title: "Rules for Operators"
5
5
6
6
The rules for infix operators have changed in some parts:
7
7
8
-
First, an alphanumeric method can be used as an infix operator only if its definition carries an `infix`{.scala} modifier. Second, it is recommended (but not enforced) to
9
-
augment definitions of symbolic operators with `@targetName`{.scala} annotations. Finally,
8
+
First, an alphanumeric method can be used as an infix operator only if its definition carries an `infix` modifier. Second, it is recommended (but not enforced) to
9
+
augment definitions of symbolic operators with `@targetName` annotations. Finally,
10
10
a syntax change allows infix operators to be written on the left in a multi-line expression.
11
11
12
12
## The `infix` Modifier
13
13
14
-
An `infix`{.scala} modifier on a method definition allows using the method as an infix operation. Example:
14
+
An `infix` modifier on a method definition allows using the method as an infix operation. Example:
15
15
16
16
```scala
17
17
importscala.annotation.targetName
@@ -54,7 +54,7 @@ any Unicode character `c` for which `java.lang.Character.isIdentifierPart(c)` re
54
54
55
55
Infix operations involving symbolic operators are always allowed, so `infix` is redundant for methods with symbolic names.
56
56
57
-
The `infix`{.scala} modifier can also be given to a type:
Copy file name to clipboardExpand all lines: docs/docs/reference/changed-features/structural-types.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -144,7 +144,7 @@ val i3 = new Vehicle: // i3: Vehicle { val range: Int }
144
144
i3.range
145
145
```
146
146
147
-
The type of `i3` in this example is `Vehicle { val range: Int }`{.scala}. Hence,
147
+
The type of `i3` in this example is `Vehicle { val range: Int }`. Hence,
148
148
`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
149
149
is implemented by the base trait `reflect.Selectable` of `Vehicle`, which
Copy file name to clipboardExpand all lines: docs/docs/reference/contextual/context-bounds.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,11 +30,11 @@ def g[T <: B : C](x: T): R = ...
30
30
## Migration
31
31
32
32
To ease migration, context bounds in Dotty map in Scala 3.0 to old-style implicit parameters
33
-
for which arguments can be passed either with a `(using ...)`{.scala} clause or with a normal application. From Scala 3.1 on, they will map to context parameters instead, as is described above.
33
+
for which arguments can be passed either with a `(using ...)` clause or with a normal application. From Scala 3.1 on, they will map to context parameters instead, as is described above.
34
34
35
35
If the source version is `3.1` and the `-migration` command-line option is set, any pairing of an evidence
36
36
context parameter stemming from a context bound with a normal argument will give a migration
37
-
warning. The warning indicates that a `(using ...)`{.scala} clause is needed instead. The rewrite can be
37
+
warning. The warning indicates that a `(using ...)` clause is needed instead. The rewrite can be
Copy file name to clipboardExpand all lines: docs/docs/reference/contextual/type-classes.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ A _type class_ is an abstract, parameterized type that lets you add new behavior
8
8
* expressing how a type you don't own (from the standard or 3rd-party library) conforms to such behavior
9
9
* expressing such a behavior for multiple types without involving sub-typing relationships (one `extends` another) between those types (see: [ad hoc polymorphism](https://en.wikipedia.org/wiki/Ad_hoc_polymorphism) for instance)
10
10
11
-
Therefore in Scala 3, _type classes_ are just _traits_ with one or more parameters whose implementations are not defined through the `extends`{.scala} keyword, but by **given instances**.
11
+
Therefore in Scala 3, _type classes_ are just _traits_ with one or more parameters whose implementations are not defined through the `extends` keyword, but by **given instances**.
12
12
Here are some examples of common type classes:
13
13
14
14
### Semigroups and monoids
@@ -272,9 +272,9 @@ end readerMonad
272
272
273
273
### Summary
274
274
275
-
The definition of a _type class_ is expressed with a parameterised type with abstract members, such as a `trait`{.scala}.
275
+
The definition of a _type class_ is expressed with a parameterised type with abstract members, such as a `trait`.
276
276
The main difference between subtype polymorphism and ad-hoc polymorphism with _type classes_ is how the definition of the _type class_ is implemented, in relation to the type it acts upon.
277
-
In the case of a _type class_, its implementation for a concrete type is expressed through a `given`{.scala} instance definition, which is supplied as an implicit argument alongside the value it acts upon. With subtype polymorphism, the implementation is mixed into the parents of a class, and only a single term is required to perform a polymorphic operation. The type class solution
277
+
In the case of a _type class_, its implementation for a concrete type is expressed through a `given` instance definition, which is supplied as an implicit argument alongside the value it acts upon. With subtype polymorphism, the implementation is mixed into the parents of a class, and only a single term is required to perform a polymorphic operation. The type class solution
278
278
takes more effort to set up, but is more extensible: Adding a new interface to a
279
279
class requires changing the source code of that class. But contrast, instances for type classes can be defined anywhere.
Copy file name to clipboardExpand all lines: docs/docs/reference/enums/desugarEnums.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,11 +23,11 @@ some terminology and notational conventions:
23
23
24
24
Simple cases and value cases are collectively called _singleton cases_.
25
25
26
-
The desugaring rules imply that class cases are mapped to case classes, and singleton cases are mapped to `val`{.scala} definitions.
26
+
The desugaring rules imply that class cases are mapped to case classes, and singleton cases are mapped to `val` definitions.
27
27
28
28
There are nine desugaring rules. Rule (1) desugars enum definitions. Rules
29
-
(2) and (3) desugar simple cases. Rules (4) to (6) define `extends`{.scala} clauses for cases that
30
-
are missing them. Rules (7) to (9) define how such cases with `extends`{.scala} clauses
29
+
(2) and (3) desugar simple cases. Rules (4) to (6) define `extends` clauses for cases that
30
+
are missing them. Rules (7) to (9) define how such cases with `extends` clauses
31
31
map into `case class`es or `val`s.
32
32
33
33
1. An `enum` definition
@@ -82,7 +82,7 @@ map into `case class`es or `val`s.
82
82
```
83
83
where `Bi` is `Li` if `Vi = '+'` and `Ui` if `Vi = '-'`. This result is then further
84
84
rewritten with rule (8). Simple cases of enums with non-variant type
85
-
parameters are not permitted (however value cases with explicit `extends`{.scala} clause are)
85
+
parameters are not permitted (however value cases with explicit `extends` clause are)
86
86
87
87
5. A class case without an extends clause
88
88
```scala
@@ -191,7 +191,7 @@ The `ordinal` method is only generated if the enum does not extend from `java.la
191
191
192
192
###ScopesforEnumCases
193
193
194
-
Acase in an `enum`{.scala} is treated similarly to a secondary constructor. It can access neither the enclosing `enum`{.scala} using `this`, nor its value parameters or instance members using simple
194
+
Acase in an `enum` is treated similarly to a secondary constructor. It can access neither the enclosing `enum` using `this`, nor its value parameters or instance members using simple
195
195
identifiers.
196
196
197
197
Even though translated enumcases are located in the enum's companion object, referencing
@@ -202,13 +202,13 @@ A Java-compatible enum is an enum that extends `java.lang.Enum`. The translation
202
202
203
203
It is a compile-time error for a Java-compatible enumto have classcases.
204
204
205
-
Cases such as `case C`{.scala} expand to a `@static val`{.scala}asopposed to a `val`{.scala}. This allows them to be generated asstatic fields of the enumtype, thus ensuring they are represented the same way as Java enums.
205
+
Cases such as `case C` expand to a `@static val` asopposed to a `val`. This allows them to be generated asstatic fields of the enumtype, thus ensuring they are represented the same way as Java enums.
206
206
207
207
###OtherRules
208
208
209
209
-A normal caseclasswhich is not produced from an enumcase is not allowed to extend
210
210
`scala.reflect.Enum`. This ensures that the only cases of an enumare the ones that are
211
211
explicitly declared in it.
212
212
213
-
-If an enumcase has an `extends`{.scala} clause, the enumclass must be one of the
213
+
-If an enumcase has an `extends` clause, the enumclass must be one of the
0 commit comments