Given something like:
class A { def f(x: X) = ... def g(y: Y, z: Z) = ... ... }
How to (automatically) extract function (s):
object A { val f' = (a: A, x: X) => af(x) // do this automagically for any arbitrary f val g' = (a: A, y: Y, z: Z) => ag(y, z) // and deal with arity > 1 too ... }
With this exact type signature (first an object, then a list of parameters). Let me state the problem very clearly:
"Given the method f(x1: X1, ..., xn: Xn) defined in the context of class A , how to automatically extract the function f' so that (i) receives an instance A type A and (ii) a list of parameters corresponding to 1: 1, to the list of parameters f , namely: x1: X, ... xn: Xn , the implementation of which is exactly af(x1: X1, ..., xn: Xn) "
Or even:
Capturing the concept of lambda calculus extensiveness such that you automatically extract λx.(fx) from f whenever x not mapped to f .
This could be solved first by finding a way to access the identifiers f , g , ... without having a specific a: A (for example, it will have a specific A defined). We could just write f' or g' hand, but let spoil DRYness.
PS Perhaps this is impossible without reflection at run time (although this is possible with Scala 2.10+ macros), since I cannot find a way to refer to the identifiers f or g without a specific instance ( a: A ) in advance. But it would be something like the following, without having to resort to strings :
A.getMethod("f"): Function2[A, X, ...]
I also understand that the practical use of the question can help participants suggest alternatives, but I discuss this in an abstract sense. I am not trying to solve another problem that I led to this. I'm trying to find out if this one is possible :-) Here is a very good article to really understand the motivation behind this issue, with circulations over Eta-decompositions on Scala.