@@ -267,7 +267,7 @@ knowing anything about the representation of `Expr` trees. For
267267instance, here is a possible instance of ` Liftable[Boolean] ` :
268268``` scala
269269given Liftable [Boolean ] {
270- def toExpr (b : Boolean )( given QuoteContext ) : Expr [ Boolean ] =
270+ def toExpr (b : Boolean ) =
271271 if (b) ' { true } else ' { false }
272272}
273273```
@@ -276,7 +276,7 @@ possible implementation of `Liftable[Int]` that does not use the underlying
276276tree machinery:
277277``` scala
278278given Liftable [Int ] {
279- def toExpr (n : Int )( given QuoteContext ) : Expr [ Int ] = n match {
279+ def toExpr (n : Int ) = n match {
280280 case Int .MinValue => ' { Int .MinValue }
281281 case _ if n < 0 => ' { - $ { toExpr(- n) } }
282282 case 0 => ' { 0 }
@@ -288,9 +288,9 @@ given Liftable[Int] {
288288Since ` Liftable ` is a type class, its instances can be conditional. For example,
289289a ` List ` is liftable if its element type is:
290290``` 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) } }
294294 case Nil => ' { Nil : List [T ] }
295295 }
296296}
@@ -303,7 +303,7 @@ analogue of lifting.
303303
304304Using lifting, we can now give the missing definition of ` showExpr ` in the introductory example:
305305``` scala
306- def showExpr [T ](expr : Expr [T ]): Expr [String ] = {
306+ def showExpr [T ](expr : Expr [T ])( given QuoteContext ) : Expr [String ] = {
307307 val code : String = expr.show
308308 Expr (code)
309309}
0 commit comments