Skip to content
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

[PROPOSAL] Operator overload for function calls #103

Closed
EliteMasterEric opened this issue Feb 7, 2023 · 3 comments
Closed

[PROPOSAL] Operator overload for function calls #103

EliteMasterEric opened this issue Feb 7, 2023 · 3 comments

Comments

@EliteMasterEric
Copy link

Haxe currently allows for abstracts to redefine unary operators such as a++, as well as binary operators, such as a + b, and even other operators such as ternary, range, or array access. However, based on the documentation I have read, it does not currently allow overriding the function call operation.

I would imagine this would look something like so:

abstract CallableThing(CallableThingBase) {
  @:op(Int, Bool)
  public function call(arg1:Int, arg2:Bool):Void {
    trace('Arg 1: $arg1');
    trace('Arg 2: $arg2');
  }
}

...

var c:CallableThing = new CallableThing();
// You can now make calls to C as though it were an Int->Bool->Void function.
c(1, true);

At compilation time, c(1, true) would be replaced with CallableThing_Impl_.call(c, 1, true).

The main sticking points here is the actual syntax; @:op(Int, Bool) is redundant since we already have the function signature, @:op(()) can't necessarily be interpreted by the compiler I don't think, and the @:callable metadata is already in use.

@Simn
Copy link
Member

Simn commented Feb 8, 2023

See #93 for an discussion on this topic.

@Simn Simn closed this as completed Feb 8, 2023
@EliteMasterEric
Copy link
Author

Hey @Simn,

After reading your linked discussion, I concluded that #93 is related (and possibly a prerequisite for this) but does not directly supersede this proposal.

This proposal is not referring to the overload keyword but to this specific feature:

https://haxe.org/manual/types-abstract-operator-overloading.html

I am essentially proposing that a new operator be added (which abstracts could replace) which would allow for abstract objects to be called as though they were anonymous functions.

@EliteMasterEric
Copy link
Author

Was reading through proposals and re-discovered this old issue I raised.

For anyone searching here, this feature was actually implemented in Haxe 4.3.0, in the form of @:op(a()).

https://try.haxe.org/#25e52a54

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

No branches or pull requests

2 participants