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: _overviews/scala3-book/ca-context-parameters.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -150,5 +150,7 @@ renderWebsite("/home")
150
150
// again no argument
151
151
```
152
152
153
+
A detailed guide to where Scala looks for canonical values can be found in [the FAQ]({% link _overviews/FAQ/index.md %}#where-does-scala-look-for-implicits).
Copy file name to clipboardExpand all lines: _overviews/scala3-book/ca-contextual-abstractions-intro.md
+12-13Lines changed: 12 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -11,8 +11,7 @@ next-page: ca-extension-methods
11
11
12
12
## Background
13
13
14
-
Implicits in Scala 2 were a major distinguishing design feature.
15
-
They are *the* fundamental way to abstract over context.
14
+
Contextual abstractions are a way to abstract over context.
16
15
They represent a unified paradigm with a great variety of use cases, among them:
17
16
18
17
- Implementing type classes
@@ -21,36 +20,36 @@ They represent a unified paradigm with a great variety of use cases, among them:
21
20
- Expressing capabilities
22
21
- Computing new types, and proving relationships between them
23
22
24
-
Since then, other languages have followed suit, e.g., Rust’s traits or Swift’s protocol extensions.
23
+
Other languages have been influenced by Scala in this regard. E.g., Rust’s traits or Swift’s protocol extensions.
25
24
Design proposals are also on the table for Kotlin as compile time dependency resolution, for C# as Shapes and Extensions or for F# as Traits.
26
-
Implicits are also a common feature of theorem provers such as Coq or Agda.
25
+
Contextual abstractions are also a common feature of theorem provers such as Coq or Agda.
27
26
28
-
Even though these designs use different terminology, they’re all variants of the core idea of *term inference*:
29
-
Given a type, the compiler synthesizes a “canonical” term that has that type.
27
+
Even though these designs use different terminology, they’re all variants of the core idea of **term inference**: given a type, the compiler synthesizes a “canonical” term that has that type.
30
28
29
+
## Scala 3 Redesign
31
30
32
-
## Redesign
31
+
In Scala 2, contextual abstractions are supported by marking definitions (methods and values) or parameters as `implicit` (see [Context Parameters]({% link _overviews/scala3-book/ca-context-parameters.md %})).
33
32
34
-
Scala 3 includes a redesign of contextual abstractions in Scala.
33
+
Scala 3 includes a redesign of contextual abstractions.
35
34
While these concepts were gradually “discovered” in Scala 2, they’re now well known and understood, and the redesign takes advantage of that knowledge.
36
35
37
36
The design of Scala 3 focuses on **intent** rather than **mechanism**.
38
37
Instead of offering one very powerful feature of implicits, Scala 3 offers several use-case oriented features:
39
38
40
39
-**Retroactively extending classes**.
41
-
In Scala 2, extension methods had to be encoded using implicit conversions or implicit classes.
40
+
In Scala 2, extension methods are encoded by using [implicit conversions][implicit-conversions] or [implicit classes]({% link _overviews/core/implicit-classes.md %}).
42
41
In contrast, in Scala 3 [extension methods][extension-methods] are now directly built into the language, leading to better error messages and improved type inference.
43
42
44
43
-**Abstracting over contextual information**.
45
44
[Using clauses][givens] allow programmers to abstract over information that is available in the calling context and should be passed implicitly.
46
45
As an improvement over Scala 2 implicits, using clauses can be specified by type, freeing function signatures from term variable names that are never explicitly referred to.
47
46
48
47
-**Providing Type-class instances**.
49
-
[Given instances][type-classes] allow programmers to define the _canonical value_ of a certain type.
50
-
This makes programming with type-classes more straightforward without leaking implementation details.
48
+
[Given instances][givens] allow programmers to define the _canonical value_ of a certain type.
49
+
This makes programming with [type-classes][type-classes] more straightforward without leaking implementation details.
51
50
52
51
-**Viewing one type as another**.
53
-
Implicit conversion have been [redesigned][implicit-conversions] from the ground up as instances of a type-class `Conversion`.
52
+
Implicit conversions have been [redesigned][implicit-conversions] from the ground up as instances of a type-class `Conversion`.
54
53
55
54
-**Higher-order contextual abstractions**.
56
55
The _all-new_ feature of [context functions][contextual-functions] makes contextual abstractions a first-class citizen.
@@ -85,4 +84,4 @@ This chapter introduces many of these new features in the following sections.
85
84
[context-bounds]: {% link _overviews/scala3-book/ca-context-bounds.md %}
86
85
[type-classes]: {% link _overviews/scala3-book/ca-type-classes.md %}
87
86
[equality]: {% link _overviews/scala3-book/ca-multiversal-equality.md %}
88
-
[contextual-functions]: {% link _overviews/scala3-book/types-dependent-function.md %}
0 commit comments