Skip to content

Instantly share code, notes, and snippets.

@JustinSDK
Last active March 19, 2018 06:02
Show Gist options
  • Save JustinSDK/4ca12f20311b94345529c25b1b151e21 to your computer and use it in GitHub Desktop.
Save JustinSDK/4ca12f20311b94345529c25b1b151e21 to your computer and use it in GitHub Desktop.
console.log([1, 2, 3].map(elem => elem - 2))?(part 1)
function array(lt) {
let pair = l => r => f => f(l)(r);
let left = p => p(l => r => l);
let right = p => p(l => r => r);
let nil = pair(undefined)(undefined);
let con = head => tail => pair(head)(tail);
let head = lt => left(lt)
let tail = lt => right(lt);
let isEmpty = lt => head(lt) === undefined;
function arr(acc, l) {
if(isEmpty(l)) {
return acc;
} else {
return arr(acc.concat([head(l)]), tail(l));
}
}
return arr([], lt);
}
/*
底下相當於 console.log([1, 2, 3].map(elem => elem - 1)),願意的話,試著挑戰看看,將 :?、數值、加、減、比較等,都轉換為 lambda ...XD
*/
console.log(array((f => (x => f(n => x(x)(n)))(x => f(n => x(x)(n))))(map => lt => f => (lt => (lt => (p => p(l => r => l))(lt))(lt) === undefined)(lt) ? ((l => r => f => f(l)(r))(undefined)(undefined)) : (head => tail => (l => r => f => f(l)(r))(head)(tail))(f((lt => (p => p(l => r => l))(lt))(lt)))(map((lt => (p => p(l => r => r))(lt))(lt))(f)))((elems => (lt => (f => (x => f(n => x(x)(n)))(x => f(n => x(x)(n))))(rev => r => l => (lt => (lt => (p => p(l => r => l))(lt))(lt) === undefined)(l) ? r : rev((head => tail => (l => r => f => f(l)(r))(head)(tail))((lt => (p => p(l => r => l))(lt))(l))(r))((lt => (p => p(l => r => r))(lt))(l)))((l => r => f => f(l)(r))(undefined)(undefined))(lt))(elems()))((f => (x => f(n => x(x)(n)))(x => f(n => x(x)(n))))(rcon => tail => head => head === undefined ? tail : rcon((head => tail => (l => r => f => f(l)(r))(head)(tail))(head)(tail)))((l => r => f => f(l)(r))(undefined)(undefined))(1)(2)(3)))(elem => elem - 1)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment