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

Implement first-class functions #467

Closed
jfecher opened this issue Nov 14, 2022 · 2 comments
Closed

Implement first-class functions #467

jfecher opened this issue Nov 14, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@jfecher
Copy link
Contributor

jfecher commented Nov 14, 2022

Problem

Noir currently has generics, but no way to abstract over operations to perform on these generics. With the absence of traits, another method to provide functionality is by manually passing in functions. This requires higher-order functions in noir, or in other words, for functions to accept other functions as parameters and return them as return values.

Solution

Add higher-order functions including function types and lambdas to Noir.

Function types:

fn()
fn(Field) -> Field
fn(i32, T) -> (T, i32)

// function takes a function and returns a function
fn(fn(T) -> U) -> fn(T) -> U

Lambdas:

|| {}
|x| x
|x, t| (x, t)
|f: fn(T) -> U| f
@jfecher jfecher added the enhancement New feature or request label Nov 14, 2022
@kevaundray
Copy link
Contributor

@jfecher can this be closed?

@jfecher
Copy link
Contributor Author

jfecher commented Jan 23, 2023

Yes, implemented in #468

@jfecher jfecher closed this as completed Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants