-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Syntax for method types or tree constructors useful in meta-programming #5563
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
Comments
I don't think we should introduce a special syntax like this that can only be used in one context, it's going to be very confusing to users. What about writing |
I agree introducing new syntax should be avoided. What about introducing an intrinsic type constructor: type MethodType[T] Where |
I belive this would be best encoded with quote extractors (which we do not have yet). It would look something like case '{ (~eq).apply(~left, ~right) } if isEqEqEq(eq) => // where eq is of type (Expr[T1], Expr[T2]) => Expr[Boolean]
'{
val _left = ~left
val _right = ~right
val _result = ~eq(_left, _right)
val _bool = Bool.binaryMacroBool(_left, ~op.toExpr, _right, _result, ~prettifier)
Assertions.assertionsHelper.macroAssert(_bool, ~clue, ~pos)
} |
@nicolasstucki The pattern match for the following: AssertionsSpec.this.convertToEqualizer[scala.Int](5).===(6)(scalactic.Equality.default[scala.Int]) is more complex: case '{ (~fun)(~left).===(~right)(~equality) } } ==> I see on easy way to give semantics to the code above. |
Fixed in #5603 , to be confirmed in ScalaTest. |
#5603 helps when we know the signature of the method statically. In the following case, we don't know the signature statically: // definition
def convertToEqualizer[T](left: T): Equalizer[T]
// usage
this.convertToEqualizer[Option[String]] Then it's difficult to explicitly give a sensible type below: val fun = fn.seal[???] It seems in such cases, constructors are more convenient. |
Close this, discussions for constructors are in #5567 . |
Uh oh!
There was an error while loading. Please reload this page.
I'm writing a ScalaTest macro, where I find it helpful to have syntax for method types.
The use case is to transform the source code:
which is desugared as:
and macro expanded to something like the follows:
The natural thing to do in the implementation is to seal the following tree as a whole:
The ideal implementation is something like the following:
Note that in the implemetation, we used the syntax for method type:
(Any)Equalizer[_]
.Or, we can provide tree constructors (Related #5438):
However, the constructor-approach is inferior: in the quote-approach overloading resolution is a given for free, while in the constructor-approach it will be a burden on macro authors or the constructors have to do overloading resolution. AFAIK, the latter is not in the scope of #5438, @nicolasstucki mentioned adapation should be avoided in constructors.
The text was updated successfully, but these errors were encountered: