Skip to content

Commit af72225

Browse files
committed
Rewrite docs
1 parent 1b8d4ce commit af72225

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/docs/reference/metaprogramming/macros.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ different directions here for `f` and `x`. The reference to `f` is
161161
legal because it is quoted, then spliced, whereas the reference to `x`
162162
is legal because it is spliced, then quoted.
163163

164-
### Types and the PCP
164+
### Lifting Types
165165

166-
In principle, The phase consistency principle applies to types as well
167-
as for expressions. But it only acts on types that are used in higher levels.
168-
This might seem too restrictive. Indeed, the
169-
definition of `reflect` above is not phase correct since there is a
166+
Types are not directly affected by the phase consistency principle.
167+
It is possible to use types defined at any level in any other level.
168+
But, if a type is used in a subsequent stage it will need to be lifted to a `Type`.
169+
The resulting value of `Type` will be subject to PCP.
170+
Indeed, the definition of `reflect` above uses `T` in the next stage, there is a
170171
quote but no splice between the parameter binding of `T` and its
171-
usage. But the code can be made phase correct by adding a binding
172-
of a `Type[T]` tag:
172+
usage. But the code can be rewritten by adding a binding of a `Type[T]` tag:
173173
```scala
174174
def reflect[T, U](f: Expr[T] => Expr[U])(given t: Type[T]): Expr[T => U] =
175175
'{ (x: $t) => ${ f('x) } }
@@ -178,8 +178,8 @@ In this version of `reflect`, the type of `x` is now the result of
178178
splicing the `Type` value `t`. This operation _is_ splice correct -- there
179179
is one quote and one splice between the use of `t` and its definition.
180180

181-
To avoid clutter, the Scala implementation tries to convert any phase-incorrect
182-
reference to a type `T` to a type-splice, by rewriting `T` to `${ summon[Type[T]] }`.
181+
To avoid clutter, the Scala implementation tries to convert any type
182+
reference to a type `T` in subsequent phases to a type-splice, by rewriting `T` to `${ summon[Type[T]] }`.
183183
For instance, the user-level definition of `reflect`:
184184

185185
```scala

0 commit comments

Comments
 (0)