Skip to content

Commit 67fd0de

Browse files
committed
Extend abstract givens example to show usage of scala.compiletime.deferred
1 parent 98ec84d commit 67fd0de

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

_posts/2024-12-05-release-notes-3.6.2.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,24 @@ This mechanism allows defining an abstract given instance that needs to be provi
8080

8181
```scala
8282
trait Order[T]
83+
trait Show[T]
8384

8485
trait Collection:
8586
// abstract member context-bound
8687
type Element: Order
87-
88-
class List[T: Order] extends Collection:
88+
// explicit abstract given
89+
given Show[Element] = compiletime.deferred
90+
91+
class List[T: {Order, Show}] extends Collection:
8992
type Element = T
90-
// given Order[Element] = ev$1 // generated by compiler, uses class context bound
91-
92-
class Set[T] extends Collection:
93+
// generated by compiler, uses class context bound
94+
// override final given Order[Element] = evidence$1
95+
// override final given Show[Element] = evidence$2
96+
97+
class Set[T: Show as show] extends Collection:
9398
type Element = T
9499
override given Order[Element] = ??? // custom implementation provided by the user
100+
// override final given Show[Element] = this.show // generated by compiler
95101
```
96102

97103
See the updated [Contextual Abstractions](https://scala-lang.org/api/3.6.2/docs/docs/reference/contextual/givens.html) chapter of the Scala 3 reference guide to learn more about these changes.

0 commit comments

Comments
 (0)