Why is Expr[A] => A
not supported during compile-time?
#21326
Unanswered
Kalin-Rudnicki
asked this question in
Metaprogramming
Replies: 2 comments 6 replies
-
You can convert |
Beta Was this translation helpful? Give feedback.
4 replies
-
Is there any advice from someone who is familiar with the scala-3 compiler of where I would look to potentially try to implement this? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was just able to write and validate a macro that is able to generate an
Expr[RegularExpression]
. I then tried to write a macro which would be able to combine multiple of theseRegularExpression
s at compile time into anEither[Failure, Success]
, and then return anExpr[Success]
, but was unable because of the nature of passing anA
to a macro requires it to become anExpr[A]
in the impl, and there seems to be no way to go fromExpr[A]
toA
.I understand that it must be an extremely complex problem, but I am also confused why this is not allowed. There is one point in my previously mentioned (working) macro impl, where I am able to do
here,
RegularExpression.parse
is a non-trivial function which utilizes:Source
.some
fromcats
Given that that works, why is it not possible to do something like:
I imagine that when
RegularExpression.parse
is called in the first example above, all the compiler knows about there is anAST
, which is essentially the same as anExpr
, right? So, why is it supported that raw code (which is basically just an AST) using non-trivial classes and functions can pre-compile these non-trivial classes and functions at compile-time, but doing the same exact thing with anExpr
is not supported?Here is the whole macro for context:
TLDR:
It makes total sense to me why I need to define
makeExpr
here, as the generated code cant really just contain a pre-compiled object (although that'd be cool if it could), but I dont see why the first example below is allowed, by the second one isnt.In the following example:
I don't understand how the
Expr
could have the same exact information as if you to were write it within the macro, and its not allowed, but if you write it within the macro, not in an Expr, it is allowed. I have very little knowledge of what the compiler is doing here, other than observing what is or is not allowed, but this seems a little unfortunate, and would be really nice to have.Beta Was this translation helpful? Give feedback.
All reactions