-
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
Add generalized tupled functions abstraction #6568
Add generalized tupled functions abstraction #6568
Conversation
757477c
to
c931c1f
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.
Interesting. However, I would say that we miss an example of a problem that is solved by this feature. None of the tests actually abstract over the arity of the functions.
c931c1f
to
15aa152
Compare
15aa152
to
24a1d00
Compare
The first motivation of this is resumed in part in https://github.com/lampepfl/dotty/blob/24a1d00e0dc0aad01711119ac5b46cf9a85b8a66/tests/run/tupled-function-extension-method.scala which captures the essence of the limitation we have in https://github.com/lampepfl/dotty/blob/master/library/src-3.x/scala/quoted/Expr.scala. There we need to implement the extension method for each of the 22 functions and we cannot scale up to any arbitrary function arity. |
Also added support for tupled implicit functions ``` TupledFunction[given (Int, Int) => Int, given ((Int, Int)) => Int] ```
All these operations can and probably should be implemented in a library.
664790c
to
f6eb444
Compare
aaafde6
to
3c2005d
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.
LGTM :-)
I think we most likely also want something that goes in the opposite direction (tupled to untupled).
Yes. I already started looking into it :) |
I think I should add the untupling before merging. |
Also improve type inference of TupledFunction[F, G] when F is not yet inferred
e40963c
to
9f02e64
Compare
@milessabin I added |
To have the same naming convention as scala.Function.{tupled|untupled}
This introduces the type class
which the compiler only instantiates if:
F
is a function type of arityN
G
is a function with a single tuple argument of sizeN
and it's types are equal to the arguments ofF
F
is equal to the return type ofG
F
andG
are the same kind of function (both are(...) => R
or both aregiven (...) => R
)F
orG
is instantiated the second one is inferredThis abstraction allows to abstract over function arities:
tupled
method on functions of arity larger than 22andThen
andcompose
directly on functions returning tuples without the need for a call totupled
(auto function tupling).