Skip to content

#bind() macro #1581

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

Closed
brson opened this issue Jan 20, 2012 · 4 comments
Closed

#bind() macro #1581

brson opened this issue Jan 20, 2012 · 4 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@brson
Copy link
Contributor

brson commented Jan 20, 2012

We can probably take advantage of lambda-blocks' type inference (may need some tweaking still to make it work in more situations) to create a bind macro or extension that works for all function types, then get rid of bind.

@brson
Copy link
Contributor Author

brson commented Jan 20, 2012

This would also be an easy way to pass functions with incompatible argument modes to higher-order functions.

@nikomatsakis
Copy link
Contributor

I was thinking... I would perhaps like to go the opposite direction and make bind more special. The idea would be to omit the bind keyword, as in Scala. This would allow constructs like:

int::range(0, 10, _).filter(is_even, _).to_list();

In an ideal world, we could even support things like "_ + " (which work in Scala). When you go that far, though, the tricky part is to decide where the bind boundary is... for example, is ".foo(_)" equivalent to "bind .foo()" or "bind _.foo(bind _)"? Both make sense (Here, bind _ would effectively be the identity function).

Still, writing "my_vec.foldl(0, _ + _)" is pretty nice.

Anyway, the way I thought to implement this kind of thing (and to rewrite bind) is basically to have an AST node similar to the one which represents "{||...}" closures right now. So we'd get the inference of what kind of closure it is "for free".

@nikomatsakis
Copy link
Contributor

#1649 discusses my proposal. It also discusses a change to the semantics of bind that occur as a result of my proposal and which would also (potentially) occur with this proposal.

@graydon
Copy link
Contributor

graydon commented Feb 15, 2012

Is this still relevant? I think it is not, given the discussion in #1649.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants