Skip to content

Commit b6e1efe

Browse files
committed
Introduce the new syntax and update the import delegates
1 parent 315c3a4 commit b6e1efe

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

docs/blog/_posts/2019-06-11-16th-dotty-milestone-release.md

+34-10
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,30 @@ aligns with Java's syntax.
7373
For more information please read our documentation on
7474
[Wildcards](https://dotty.epfl.ch/docs/reference/changed-features/wildcards.html).
7575

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+
76100
## Polymorphic function types
77101

78102
We add preliminary support for _polymorphic function types_. Nowadays, when we
@@ -117,33 +141,33 @@ recovered by using the newly-introduced `@threadUnsafe`.
117141
For more information please read our documentation on the
118142
[threadUnsafe annotation](https://dotty.epfl.ch/docs/reference/other-new-features/threadUnsafe-annotation.html).
119143

120-
## Introducing `for` clauses for importing implied imports by type
144+
## Introducing `for` clauses for importing delegate imports by type
121145

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
123147
them by their name, and wildcard imports are typically used instead. By-type
124148
imports provide a more specific alternative to wildcard imports, which makes it
125149
clearer what is imported. Example:
126150

127151
```scala
128-
import implied A.{for TC}
152+
import delegate A.{for TC}
129153
```
130154

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`.
132156
There can be several bounding types following a `for` and bounding types can
133157
contain wildcards.
134158
For instance, assuming the object
135159

136160
```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]
142166
}
143167
```
144168
the import
145169
```
146-
import implied Instances.{for Ordering[_], ExecutionContext}
170+
import delegate Instances.{for Ordering[_], ExecutionContext}
147171
```
148172
would import the `intOrd`, `listOrd`, and `ec` instances but leave out the `im`
149173
instance, since it fits none of the specified bounds.

0 commit comments

Comments
 (0)