Last active
January 8, 2018 05:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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