Skip to content

Instantly share code, notes, and snippets.

@SergProduction
Created December 1, 2017 21:45
Show Gist options
  • Select an option

  • Save SergProduction/2899693bf491b36bea3009d503065792 to your computer and use it in GitHub Desktop.

Select an option

Save SergProduction/2899693bf491b36bea3009d503065792 to your computer and use it in GitHub Desktop.
function cons(a, b) {
return p => p(a)(b)
}
function car(pair) {
return pair(a => b => a)
}
function cdr(pair) {
return pair(a => b => b)
}
console.log(car(cons('a', 'b')) == 'a');
console.log(cdr(cons('a', 'b')) == 'b');
console.log(cdr(cdr(cons('a', cons('b', 'c')))) == 'c');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment