Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Create a proxy object for ambiguous method references #576

Open
yloiseau opened this issue Dec 10, 2020 · 0 comments
Open

Create a proxy object for ambiguous method references #576

yloiseau opened this issue Dec 10, 2020 · 0 comments

Comments

@yloiseau
Copy link
Contributor

We can't currently fully use the function reference literal notation or the Predefined::fun function on an overloaded function. This feature is only usable if the overloaded version don't have the same number of parameters, regardless of the type.
For instance, the given code:

let f = ^java.lang.Character::toLowerCase

raises a org.eclipse.golo.runtime.AmbiguousFunctionReferenceException, since two versions exists: with a char argument and with an int one.
This limits some functional style programming aspects (e.g. HOF, point-free, etc.)
The current workaround is to use a lambda |c| -> java.lang.Character.toLowerCase(c), since in that case, the resolution is done at call time using the actual arguments. A macro could be used to create such lambda directly, but it has several drawbacks:

  • more verbose to use,
  • introduce overhead if not needed, and thus shouldn't be applied systematically,
  • fixes the arity (this could be fixed by using a polyadic lambda with a test on the actual number or arguments, but become ambiguous when the referenced function itself is polyadic).

The idea, as suggested by @artpej in #326 (comment), is to use a proxy object for ambiguous method references, allowing to resolve at call time.
Such object can include an inline cache and be replaced at the call site by the real reference when known.
This would also allow more polymorphic behaviour, since with could dispatch on function with different arities.
It may be a step toward lisp-like multimethods 😉

See also #326, #341

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant