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
@@ -48,29 +59,35 @@ final implicit def given_Context = ctx
48
59
### Anonymous Given Instances
49
60
50
61
Anonymous given instances get compiler synthesized names, which are generated in a reproducible way from the implemented type(s). For example, if the names of the `IntOrd` and `ListOrd` givens above were left out, the following names would be synthesized instead:
62
+
51
63
```scala
52
64
givengiven_Ord_Int as Ord[Int] { ... }
53
65
givengiven_Ord_List_T[T](usingord: Ord[T]) as Ord[List[T]] { ... }
54
66
```
67
+
55
68
The synthesized type names are formed from
56
69
57
-
- the prefix `given_`,
58
-
- the simple name(s) of the implemented type(s), leaving out any prefixes,
59
-
- the simple name(s) of the toplevel argument type constructors to these types.
70
+
1. the prefix `given_`,
71
+
2. the simple name(s) of the implemented type(s), leaving out any prefixes,
72
+
3. the simple name(s) of the toplevel argument type constructors to these types.
60
73
61
74
Tuples are treated as transparent, i.e. a type `F[(X, Y)]` would get the synthesized name
62
75
`F_X_Y`. Directly implemented function types `A => B` are represented as `A_to_B`. Function types used as arguments to other type constructors are represented as `Function`.
63
76
64
-
### Given Clauses
77
+
### Using Clauses
78
+
79
+
Using clauses correspond largely to Scala-2's implicit parameter clauses. E.g.
65
80
66
-
Given clauses correspond largely to Scala-2's implicit parameter clauses. E.g.
67
81
```scala
68
82
defmax[T](x: T, y: T)(usingord: Ord[T]):T
69
83
```
84
+
70
85
would be written
86
+
71
87
```scala
72
88
defmax[T](x: T, y: T)(implicitord: Ord[T]):T
73
89
```
90
+
74
91
in Scala 2. The main difference concerns applications of such parameters.
75
92
Explicit arguments to parameters of using clauses _must_ be written using `(using ...)`,
76
93
mirroring the definition syntax. E.g, `max(2, 3)(using IntOrd)`.
@@ -88,29 +105,33 @@ Context bounds are the same in both language versions. They expand to the respec
88
105
89
106
**Note:** To ease migration, context bounds in Dotty map for a limited time to old-style implicit parameters for which arguments can be passed either in a using clause or
90
107
in a normal argument list. Once old-style implicits are deprecated, context bounds
91
-
will map to with clauses instead.
108
+
will map to using clauses instead.
92
109
93
110
### Extension Methods
94
111
95
112
Extension methods have no direct counterpart in Scala 2, but they can be simulated with implicit classes. For instance, the extension method
Abstract extension methods in traits that are implemented in given instances have no direct counterpart in Scala-2. The only way to simulate these is to make implicit classes available through imports. The Simulacrum macro library can automate this process in some cases.
106
127
107
128
### Type class Derivation
108
129
109
130
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.
110
131
111
-
### Implicit Function Types
132
+
### Context Function Types
112
133
113
-
Implicit function types have no analogue in Scala 2.
134
+
Context function types have no analogue in Scala 2.
114
135
115
136
### Implicit By-Name Parameters
116
137
@@ -121,16 +142,21 @@ Implicit by-name parameters are not supported in Scala 2, but can be emulated to
121
142
### Implicit Conversions
122
143
123
144
Implicit conversion methods in Scala 2 can be expressed as given instances of the `scala.Conversion` class in Dotty. E.g. instead of
0 commit comments