Description
I took the plunge and tried out some of the examples from the documentation but barely any of them compiled without modification.
I am using dotty 0.14 which was the most recent version on nixpkgs.
First thing to note is that the syntax for a splice is now $ rather than ~ as in the paper. All the examples are already consistent about this but it's a bit confusing to translate examples from the paper.
Some examples of failures:
def reflect[T : Type, U](f: Expr[T] => Expr[U]) given (t: Type[T]): Expr[T => U] =
'{ (x: $t) => ${ f('x) } }
needs to be modified to
def reflect[T:Type, U:Type](f: Expr[T] => Expr[U]) given (t: Type[T]): Expr[T => U] =
'{ (x: $t) => ${ f('x) } }
similarly to the second example.
The Array
example is not consistent and broken. The Array
class does not have the same interface as is used in the Macros
object. If you use the built-in Array
class then after adding some more annotations then Array
still fails as it needs an evidence variable which can't be persisted. If you do use the suggested Array
class then the example is even more broken as it doesn't implement length
for instance.
That's as far as I got before stopping trying to understand the implementation. I'm really eager to understand the implementation in dotty so hopefully the documentation can be refined for a future version.