1- ## Working with Given Instances and Using Clauses
1+ ## Working with Contextual Abstractions
22
33``` scala mdoc:invisible
44// Forward definitions
@@ -36,7 +36,7 @@ Working with type classes in Scala means
3636working with given instances and using clauses.
3737There are a few rules we need to know to do this effectively.
3838
39- ### Implicit Scope
39+ ### Contextual Abstractions Scope
4040
4141As we saw above, the compiler searches
4242for candidate type class instances by type.
@@ -49,10 +49,10 @@ Json.toJson("A string!")
4949```
5050
5151The places where the compiler searches for candidate instances
52- is known as the * implicit scope* .
53- The implicit scope applies at the call site;
52+ is known as the * contextual abstractions scope* .
53+ The contextual abstractions scope applies at the call site;
5454that is the point where we call a method with a using clause.
55- The implicit scope which roughly consists of:
55+ The contextual abstractions scope which roughly consists of:
5656
5757- local or inherited definitions;
5858
@@ -101,14 +101,14 @@ For our purposes, we can package type class instances in roughly five ways:
101101
102102With option 1 and 2 we bring given instances into scope by ` importing ` them explicitly.
103103With option 3 we bring them into scope with inheritance.
104- With options 4 and 5 instances are * always* in implicit scope,
104+ With options 4 and 5 instances are * always* in the contextual abstractions scope,
105105regardless of where we try to use them.
106106
107107It is conventional to put type class instances in a companion object (option 4 and 5 above)
108108if there is only one sensible implementation,
109109or at least one implementation that is widely accepted as the default.
110110This makes type class instances easier to use
111- as no import is required to bring them into the implicit scope.
111+ as no import is required to bring them into the contextual abstractions scope.
112112
113113[ ^ implicit-search ] : If you're interested in the finer rules of implicit resolution in Scala,
114114start by taking a look at [ this Stack Overflow post on implicit scope] [ link-so-implicit-scope ]
@@ -203,7 +203,9 @@ a combination that creates a type class instance
203203of the correct overall type.
204204
205205<div class =" callout callout-warning " >
206- * Implicit Conversions*
206+ * Contextual Implicit Conversions*
207+
208+ // TODO: https://docs.scala-lang.org/scala3/reference/contextual/conversions.html
207209
208210When you create a type class instance constructor
209211using an ` given ` ,
@@ -230,11 +232,6 @@ trait JsonWriter[A]:
230232``` scala modc:warn
231233given optionWriter [A ](writer : JsonWriter [A ]): JsonWriter [Option [A ]] =
232234 ???
233- // warning: implicit conversion method foo should be enabled
234- // by making the implicit value scala.language.implicitConversions visible.
235- // This can be achieved by adding the import clause 'import scala.language.implicitConversions'
236- // or by setting the compiler option -language:implicitConversions.
237- // See the Scaladoc for value scala.language.implicitConversions for a discussion
238- // why the feature should be explicitly enabled.
235+ // TODO: Fix formatting
239236```
240237</div >
0 commit comments