@@ -183,28 +183,28 @@ Types are not directly affected by the phase consistency principle.
183
183
It is possible to use types defined at any level in any other level.
184
184
But, if a type is used in a subsequent stage it will need to be lifted to a ` Type ` .
185
185
The resulting value of ` Type ` will be subject to PCP.
186
- Indeed, the definition of ` reflect ` above uses ` T ` in the next stage, there is a
186
+ Indeed, the definition of ` to ` above uses ` T ` in the next stage, there is a
187
187
quote but no splice between the parameter binding of ` T ` and its
188
188
usage. But the code can be rewritten by adding a binding of a ` Type[T] ` tag:
189
189
``` scala
190
- def reflect [T , U ](f : Expr [T ] => Expr [U ])(using t : Type [T ]): Expr [T => U ] =
190
+ def to [T , R : Type ](f : Expr [T ] => Expr [R ])(using t : Type [T ])( using QuoteContext ) : Expr [T => R ] =
191
191
' { (x : $t) => $ { f(' x ) } }
192
192
```
193
- In this version of ` reflect ` , the type of ` x ` is now the result of
193
+ In this version of ` to ` , the type of ` x ` is now the result of
194
194
splicing the ` Type ` value ` t ` . This operation _ is_ splice correct -- there
195
195
is one quote and one splice between the use of ` t ` and its definition.
196
196
197
197
To avoid clutter, the Scala implementation tries to convert any type
198
198
reference to a type ` T ` in subsequent phases to a type-splice, by rewriting ` T ` to ` ${ summon[Type[T]] } ` .
199
- For instance, the user-level definition of ` reflect ` :
199
+ For instance, the user-level definition of ` to ` :
200
200
201
201
``` scala
202
- def reflect [T : Type , U : Type ](f : Expr [T ] => Expr [U ]) : Expr [T => U ] =
202
+ def to [T : Type , R : Type ](f : Expr [T ] => Expr [R ])( using QuoteContext ) : Expr [T => R ] =
203
203
' { (x : T ) => $ { f(' x ) } }
204
204
```
205
205
would be rewritten to
206
206
``` scala
207
- def reflect [T : Type , U : Type ](f : Expr [T ] => Expr [U ]) : Expr [T => U ] =
207
+ def to [T : Type , R : Type ](f : Expr [T ] => Expr [R ])( using QuoteContext ) : Expr [T => R ] =
208
208
' { (x : $ { summon[Type [T ]] }) => $ { f(' x ) } }
209
209
```
210
210
The ` summon ` query succeeds because there is a given instance of
0 commit comments