-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace AsFunction implicit class with Expr.reduce #7299
Replace AsFunction implicit class with Expr.reduce #7299
Conversation
b44e0ff
to
30915f0
Compare
30915f0
to
57b59b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, LGTM
```scala | ||
AsFunction(_).apply: Expr[S => T] => (Expr[S] => Expr[T]) | ||
Expr.reduce(_).apply: Expr[(T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R]) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call it distribute
? From wikipedia:
K, Distribution Axiom: □(p → q) → (□p → □q).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
distribite
is not precise, it only captures a generic property in the types. It would not describe what the method actually does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also reduce
itself is not a distribution, reduce(_)
is the a distribution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @liufengyun. Reduce is counter intuitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have another suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following sentence does not read well, given the literal meaning of beta-reduction:
The
Expr
companion object contains abetaReduce
conversion that turns a tree
describing a function into a function mapping trees to trees.
library/src/scala/quoted/Expr.scala
Outdated
import qctx.tasty._ | ||
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[_]](qctx).unseal)).seal.asInstanceOf[Expr[R]]) | ||
} | ||
/** `Expr.reduceGiven(f)(x1, ..., xn)` is functionally the same as `'{($f)(given $x1, ..., $xn)}`, however it optimizes this call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A function with a given
parameter list is still considered contextual so keeping the terminology Contextual
is still relevant. WDYT about reduceGiven
to distributeContextual
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I considered
Contextual
but it is a bit long (though it could be acceptable) - The operation does not do a distribution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In partial evaluation literature reduce
is usually a function for symbolic reduction expressions that returns either a value (a number or an S expression) or a reduced residual expression) according to whether the passed e
is static or dynamic (Section 5.4.2 in Partial Evaluation and Automatic Code Generation).
What about callStatic
or something else?
@@ -1,6 +1,6 @@ | |||
import scala.quoted._ | |||
|
|||
def testImpl(f: Expr[(Int, Int) => Int])(given QuoteContext): Expr[Int] = f('{1}, '{2}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, by reading this reduce
confuses a lot.
This function does exactly one step of that reduction depending if the |
It is a nitpick because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.