@@ -73,6 +73,30 @@ aligns with Java's syntax.
73
73
For more information please read our documentation on
74
74
[ Wildcards] ( https://dotty.epfl.ch/docs/reference/changed-features/wildcards.html ) .
75
75
76
+ # Syntax Change: Contextual Abstractions
77
+
78
+ We reconsider the syntax for contextual abstractions introducing ` delegates `
79
+ (formerly known as ` implied ` ). ` delegate ` , in the context of contextual
80
+ abstraction means that we declare a _ representative of a type_ . We use
81
+ ` delegate ` as a noun. Note that this change is solely syntactical/grammatical
82
+ and its motivation is to give a clearer meaning to those _ canonical_ values of
83
+ certain types (like ` Ord[Int] ` ), that serve for synthesizing arguments to
84
+ ` given ` clauses.
85
+
86
+ ``` scala
87
+ delegate IntOrd for Ord [Int ] {
88
+ def compare (x : Int , y : Int ) =
89
+ if (x < y) - 1 else if (x > y) + 1 else 0
90
+ }
91
+ ```
92
+
93
+ ``` scala
94
+ delegate ListOrd [T ] for Ord [List [T ]] given (ord : Ord [T ]) {
95
+ ```
96
+
97
+ For more information, the documentation has been updated as part of the relevant
98
+ PR [# 6649 ](https:// github.com/ lampepfl/ dotty/ pull/ 6649 )
99
+
76
100
## Polymorphic function types
77
101
78
102
We add preliminary support for _polymorphic function types_. Nowadays , when we
@@ -117,33 +141,33 @@ recovered by using the newly-introduced `@threadUnsafe`.
117
141
For more information please read our documentation on the
118
142
[threadUnsafe annotation](https:// dotty.epfl.ch/ docs/ reference/ other- new - features/ threadUnsafe- annotation.html).
119
143
120
- ## Introducing ` for ` clauses for importing implied imports by type
144
+ ## Introducing `for` clauses for importing delegate imports by type
121
145
122
- Since implied instances can be anonymous it is not always practical to import
146
+ Since delegate instances can be anonymous it is not always practical to import
123
147
them by their name, and wildcard imports are typically used instead. By - type
124
148
imports provide a more specific alternative to wildcard imports, which makes it
125
149
clearer what is imported. Example :
126
150
127
151
```scala
128
- import implied A .{for TC }
152
+ import delegate A .{for TC }
129
153
```
130
154
131
- This imports any implied instance in ` A ` that has a type which conforms tp ` TC ` .
155
+ This imports any delegate instance in `A` that has a type which conforms tp `TC`.
132
156
There can be several bounding types following a `for` and bounding types can
133
157
contain wildcards.
134
158
For instance, assuming the object
135
159
136
160
```scala
137
- object Instances {
138
- implied intOrd for Ordering [Int ]
139
- implied [T : Ordering ] listOrd for Ordering [List [T ]]
140
- implied ec for ExecutionContext = ...
141
- implied im for Monoid [Int ]
161
+ object Delegates {
162
+ delegate intOrd for Ordering [Int ]
163
+ delegate [T : Ordering ] listOrd for Ordering [List [T ]]
164
+ delegate ec for ExecutionContext = ...
165
+ delegate im for Monoid [Int ]
142
166
}
143
167
```
144
168
the import
145
169
```
146
- import implied Instances.{for Ordering[_], ExecutionContext}
170
+ import delegate Instances .{for Ordering [_ ], ExecutionContext }
147
171
```
148
172
would import the `intOrd` , `listOrd` , and `ec` instances but leave out the `im`
149
173
instance, since it fits none of the specified bounds.
0 commit comments