Skip to content

Instantly share code, notes, and snippets.

@remo5000
Last active January 8, 2018 05:49
Show Gist options
  • Save remo5000/701364a1d3b9da54339d429dcc5e3672 to your computer and use it in GitHub Desktop.
Save remo5000/701364a1d3b9da54339d429dcc5e3672 to your computer and use it in GitHub Desktop.
Interesting functions used in an academic functional programming question. Reference for a blog post.
function plus_one(x) {
return x + 1;
}
function twice(f) {
return function(x) {
return f(f(x));
};
}
function n_times(f, n) {
if (n === 1) {
return f;
} else {
return function(x) {
return f((n_times(f, n - 1))(x));
};
}
}
function chain(f, n) {
if (n === 1) {
return f;
} else {
return (chain(f, n - 1))(f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment