@@ -267,7 +267,7 @@ knowing anything about the representation of `Expr` trees. For
267
267
instance, here is a possible instance of ` Liftable[Boolean] ` :
268
268
``` scala
269
269
given Liftable [Boolean ] {
270
- def toExpr (b : Boolean )( given QuoteContext ) : Expr [ Boolean ] =
270
+ def toExpr (b : Boolean ) =
271
271
if (b) ' { true } else ' { false }
272
272
}
273
273
```
@@ -276,7 +276,7 @@ possible implementation of `Liftable[Int]` that does not use the underlying
276
276
tree machinery:
277
277
``` scala
278
278
given Liftable [Int ] {
279
- def toExpr (n : Int )( given QuoteContext ) : Expr [ Int ] = n match {
279
+ def toExpr (n : Int ) = n match {
280
280
case Int .MinValue => ' { Int .MinValue }
281
281
case _ if n < 0 => ' { - $ { toExpr(- n) } }
282
282
case 0 => ' { 0 }
@@ -288,9 +288,9 @@ given Liftable[Int] {
288
288
Since ` Liftable ` is a type class, its instances can be conditional. For example,
289
289
a ` List ` is liftable if its element type is:
290
290
``` scala
291
- given [T : Liftable ] : Liftable [List [T ]] {
292
- def toExpr (xs : List [T ])( given QuoteContext ) : Expr [ List [ T ]] = xs match {
293
- case head :: tail => ' { $ { toExpr (head) } :: $ { toExpr(tail) } }
291
+ given [T : Liftable : Type ] : Liftable [List [T ]] {
292
+ def toExpr (xs : List [T ]) = xs match {
293
+ case head :: tail => ' { $ { Expr (head) } :: $ { toExpr(tail) } }
294
294
case Nil => ' { Nil : List [T ] }
295
295
}
296
296
}
@@ -303,7 +303,7 @@ analogue of lifting.
303
303
304
304
Using lifting, we can now give the missing definition of ` showExpr ` in the introductory example:
305
305
``` scala
306
- def showExpr [T ](expr : Expr [T ]): Expr [String ] = {
306
+ def showExpr [T ](expr : Expr [T ])( given QuoteContext ) : Expr [String ] = {
307
307
val code : String = expr.show
308
308
Expr (code)
309
309
}
0 commit comments