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/eta-expansion-spec.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,13 @@ layout: doc-page
3
3
title: "Automatic Eta Expansion - More Details"
4
4
---
5
5
6
-
###Motivation
6
+
## Motivation
7
7
8
8
Scala maintains a convenient distinction between _methods_ and _functions_.
9
9
Methods are part of the definition of a class that can be invoked in objects while functions are complete objects themselves, making them first-class entities. For example, they can be assigned to variables.
10
-
These two mechanisms are bridged in Scala by a mechanism called _eta-expansion_ (also called eta-abstraction), which converts a reference to a method into a function. Intuitively, a method `m` can be passed around by turning it into an object: the function `x => m(x)`.
10
+
These two mechanisms are bridged in Scala by a mechanism called
(also called eta-abstraction), which converts a reference to a method into a function. Intuitively, a method `m` can be passed around by turning it into an object: the function `x => m(x)`.
11
13
12
14
In this snippet which assigns a method to a `val`, the compiler will perform _automatic eta-expansion_, as shown in the comment:
13
15
@@ -69,6 +71,6 @@ Thus, an unapplied method with an empty argument list is only converted to a fun
69
71
70
72
The method value syntax `m _` is deprecated.
71
73
72
-
###Reference
74
+
## Reference
73
75
74
76
For more info, see [PR #2701](https://github.com/lampepfl/dotty/pull/2701).
Copy file name to clipboardExpand all lines: docs/docs/reference/changed-features/implicit-resolution.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
@@ -2,7 +2,7 @@
2
2
layout: doc-page
3
3
title: "Changes in Implicit Resolution"
4
4
---
5
-
This page describes changes to the implicit resolution that apply both to the new `given`s and to the old-style `implicit`s in Scala 3.
5
+
This section describes changes to the implicit resolution that apply both to the new `given`s and to the old-style `implicit`s in Scala 3.
6
6
Implicit resolution uses a new algorithm which caches implicit results
7
7
more aggressively for performance. There are also some changes that
8
8
affect implicits on the language level.
@@ -20,8 +20,8 @@ where the type may still be inferred:
20
20
/*!*/implicitdefy= ... // error: type must be given explicitly
21
21
22
22
valy= {
23
-
implicitvalctx=this.ctx // ok
24
-
...
23
+
implicitvalctx=this.ctx // ok
24
+
...
25
25
}
26
26
```
27
27
**2.**Nesting is now taken into account for selecting an implicit. Considerfor instance the following scenario:
@@ -114,7 +114,7 @@ the implicit search for `Q` fails.
114
114
**5.**The treatment of divergence errors has also changed. A divergent implicit is treated asa normal failure, after which alternatives are still tried. This also makes sense: Encountering a divergent implicit means that we assume that no finite solution can be found on the corresponding path, but another path can still be tried. By contrast,
115
115
most (but not all) divergence errors in Scala2 would terminate the implicit search asa whole.
116
116
117
-
**6.**Scala-2 gives a lower level of priority to implicit conversions with call-by-name parameters relative to implicit conversions with call-by-value parameters. Scala3 drops this distinction. So the following code snippet would be ambiguous in Scala3:
117
+
**6.**Scala2 gives a lower level of priority to implicit conversions with call-by-name parameters relative to implicit conversions with call-by-value parameters. Scala3 drops this distinction. So the following code snippet would be ambiguous in Scala3:
Copy file name to clipboardExpand all lines: docs/docs/reference/contextual/conversions.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,8 @@ title: "Implicit Conversions"
6
6
Implicit conversions are defined by given instances of the `scala.Conversion` class.
7
7
This class is defined in package `scala` as follows:
8
8
```scala
9
-
abstractclassConversion[-T, +U] extends (T=>U)
9
+
abstractclassConversion[-T, +U] extends (T=>U):
10
+
defapply (x: T):U
10
11
```
11
12
For example, here is an implicit conversion from `String` to `Token`:
12
13
```scala
@@ -41,7 +42,7 @@ given int2Integer: Conversion[Int, java.lang.Integer] =
41
42
java.lang.Integer.valueOf(_)
42
43
```
43
44
44
-
2. The "magnet" pattern is sometimes used to express many variants of a method. Instead of defining overloaded versions of the method, one can also let the method take one or more arguments of specially defined "magnet" types, into which various argument types can be converted. E.g.
45
+
2. The "magnet" pattern is sometimes used to express many variants of a method. Instead of defining overloaded versions of the method, one can also let the method take one or more arguments of specially defined "magnet" types, into which various argument types can be converted. Example:
Copy file name to clipboardExpand all lines: docs/docs/reference/contextual/motivation.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
@@ -7,7 +7,7 @@ title: "Overview"
7
7
8
8
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.
9
9
10
-
Following Haskell, Scala was the second popular language to have some form of implicits. Other languages have followed suit. E.g Rust's traits or Swift's protocol extensions. 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)
10
+
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
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).
12
12
13
13
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.
0 commit comments