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

.bind() ignores optional arguments when returns new binded function #3082

Closed
grisevg opened this issue May 30, 2014 · 9 comments
Closed

.bind() ignores optional arguments when returns new binded function #3082

grisevg opened this issue May 30, 2014 · 9 comments

Comments

@grisevg
Copy link

grisevg commented May 30, 2014

Haxe 3.1.3.
Piece of code says it's better than a thousand words:

var foo = function(lo:Int, bar:String):Void {}
var foo2 = function(?lo:Int, ?bar:String):Void {}
$type(foo.bind(5)); // String -> Void
$type(foo2.bind(5)); // Void -> Void

$type(foo2.bind(5)); should be ?String -> Void instead.

@frabbit
Copy link
Member

frabbit commented May 30, 2014

that's how bind works. If you don't want to bind optional arguments you have to do it explicit like:
foo2.bind(5,_)

@grisevg
Copy link
Author

grisevg commented May 30, 2014

wooooow.... thank you! it would be very useful to say that in official docs :D

@frabbit
Copy link
Member

frabbit commented May 30, 2014

that's why i created an issue for this ;)

@grisevg
Copy link
Author

grisevg commented May 30, 2014

thank you very much

@grisevg grisevg closed this as completed May 30, 2014
@Simn
Copy link
Member

Simn commented May 30, 2014

I wonder why we designed it like that...

@frabbit
Copy link
Member

frabbit commented May 30, 2014

I don't know, do you think it would be better to not bind optional arguments by default? I guess that's a matter of taste.

@ncannasse
Copy link
Member

Both are arbitrary choice, but I found by experience that in general you want to have the optional arguments ignored, hence the design

@Simn
Copy link
Member

Simn commented May 31, 2014

But you could still ignore them when calling the resulting function, which is why it seems to be more flexible that way.

@ncannasse
Copy link
Member

The problem is that you cannot erase optional arguments when unifying functions.

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

4 participants