Skip to content

Add curry! macro #6634

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
wants to merge 1 commit into from
Closed

Conversation

brendanzab
Copy link
Member

This adds a curry! macro that defines a named or anonymous curried function.

Example:

curry!(
    fn mul(x: int, y: int) -> int {
        x * y
    }
)

assert_eq!(mul(2)(3), 6);

let mul2 = mul(2);
assert_eq!(mul2(3), 6);

let f: @fn(int) -> @fn(int) -> int = curry!(|x,y| x * y);
assert_eq!(f(2)(3), 6);

Notes:

  • It would be nicer if the syntax for named declarations could be
    fn foo x: int -> y: int -> int to reinforce the curried nature of the
    resulting function, but this causes an ambiguity during macro expansion.
  • Unfortunately generics are not supported due to the difficulty of
    implementing type parameter lists in macros.
  • Anonymous curried functions have difficulty inferring types.

@brson
Copy link
Contributor

brson commented May 20, 2013

I'm a little wary of adding this to the compiler. Any macros we add now Rust is going to have to maintain forever, even after we have macro importing. Is curry!, as written here how we want to do currying in Rust forevermore?

Any other opinions?

@lifthrasiir
Copy link
Contributor

Syntactic opinion, inspired by Scala and other languages:

curry!(
    fn mul(x: int)(y: int) -> int {
        x * y
    }
)

For now, I agree to @brson that this macro does not merit the inclusion in the compiler. Importable/exportable macro (#3114) may allow adding such utility macros that is "not necessary but helpful from time to time" (e.g. my old iif! proposal) to the standard library however.

@brendanzab
Copy link
Member Author

Sure thing, valid points. I'll close for now.

@brendanzab brendanzab closed this May 21, 2013
@brendanzab brendanzab deleted the curry-macro branch May 21, 2013 02:02
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

Successfully merging this pull request may close these issues.

3 participants