Skip to content

Instantly share code, notes, and snippets.

@hackaugusto
Created December 8, 2013 22:53
Show Gist options
  • Select an option

  • Save hackaugusto/7864860 to your computer and use it in GitHub Desktop.

Select an option

Save hackaugusto/7864860 to your computer and use it in GitHub Desktop.
fn double(f: &|int| -> int, a: int) -> int {
(*f)(a) * 2
}
fn borrow(f: &|int| -> int) -> int {
let r = double(f,1);
(*f)((*f)(r))
}
fn main() {
print!("{}", borrow(&|a:int| a+1));
}
@chris-morgan
Copy link
Copy Markdown

In &|a: int| a + 1, the type annotation for a is optional; |a| a + 1 would work just as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment