# 真的未定義？

``````let len = l => when(isEmpty(l))
(_ => \$0)

let sum = l => when(isEmpty(l))
(_ => \$0)
``````

``````let y = f => (x => f(n => x(x)(n)))(x => f(n => x(x)(n)));

let undef = (_ => _)();
let is_undef = n => n === undef ? yes : no;

let yes = f => _ => f();
let no = _ => f => f();
let when = _ => _;

let not = b => b(_ => no)(_ => yes);

let pair = l => r => f => f(l)(r);
let left = p => p(l => _ => l);
let right = p => p(_ => r => r);

let nil = pair(undef)(undef);
let con = h => t => pair(h)(t);
let tail = right;

let isEmpty = l => is_undef(head(l));

let \$0 = _ => x => x;
let \$1 = f => x => f(x);
let \$2 = f => x => f(f(x));
let \$3 = f => x => f(f(f(x)));

let is_\$0 = n => n(_ => no)(yes);

let succ = n => f => x => f(n(f)(x));
let add = m => n => n(succ)(m);

let pair_succ = p => pair(right(p))(succ(right(p)));
let prev = n => left(n(pair_succ)(pair(\$0)(\$0)));
let sub = m => n => n(prev)(m);

let len = l => when(isEmpty(l))
(_ => \$0)

let sum = l => when(isEmpty(l))
(_ => \$0)

let rcon = t => h => when(is_undef(h))
(_ => t)
(_ => rcon(con(h)(t)));

let rev = r => l => when(isEmpty(l))
(_ => r)

let reverse = l => rev(nil)(l);

let elems = rcon(nil);

let list = es => reverse(es());

let map = l => f => when(isEmpty(l))
(_ => nil)

let lt = list(elems(\$1)(\$2)(\$3));
let lt2 = map(list(elems(\$1)(\$2)(\$3)))(elem => sub(elem)(\$1));

console.log(natural(len(lt)));
console.log(natural(sum(lt)));
console.log(array(lt2));

function natural(n) {
return n(i => i + 1)(0);
}

function array(lt) {
function arr(acc, l) {
if(isEmpty(l) === yes) {
return acc;
} else {
}
}
return arr([], lt);
}
``````

YA？還是不太甘心啊！都已經將 `===``?:` 逼到 `is_undef` 了，就不能給它們一個痛快嗎？（咦？）…

``````let nil = _ => yes;
``````

`f` 是什麼都不重要，因此用 `_` 來表示就可以了。現在解決了 `isEmpty` 一半的問題，只要遇到 `nil` 就可以傳回 `yes`，那麼其他的 List 呢？只有 `nil` 會直接忽略傳入的函式直接傳回 `yes`，既然如此，其他的 List 會呼叫傳入的函式，那麼傳入的函式一律傳回 `no` 就可以了：

``````let isEmpty = l => l(_ => _ => no);
``````

``````let is_nil = l => l(_ => _ => no);
let isEmpty = is_nil;
``````

``````let is_\$\$ = n => n(_ => no)(no);
``````

``````let \$\$ = _ => _ => yes;
``````

``````let rcon = t => h => when(is_\$\$(h))
(_ => t)
(_ => rcon(con(h)(t)));
``````

YA！終於連 `rcon` 都沒使用 `is_undef` 了，別忘了 `list` 也要做個修改，最後必須傳入 `\$\$`

``````let list = es => reverse(es(\$\$));
``````

``````let unit = _ => _;
let no_use = unit;

let yes = f => _ => f(no_use);
let no = _ => f => f(no_use);
let when = unit;
``````

``````let y = f => (x => f(n => x(x)(n)))(x => f(n => x(x)(n)));

let unit = _ => _;
let no_use = unit;

let yes = f => _ => f(no_use);
let no = _ => f => f(no_use);
let when = unit;

let not = b => b(_ => no)(_ => yes);

let pair = l => r => f => f(l)(r);
let left = p => p(l => _ => l);
let right = p => p(_ => r => r);

let nil = _ => yes;
let con = h => t => pair(h)(t);
let tail = right;

let is_nil = l => l(_ => _ => no);
let isEmpty = is_nil;

let \$0 = _ => x => x;
let \$1 = f => x => f(x);
let \$2 = f => x => f(f(x));
let \$3 = f => x => f(f(f(x)));
let is_\$0 = n => n(_ => no)(yes);

let \$\$ = _ => _ => yes;
let is_\$\$ = n => n(_ => no)(no);

let succ = n => f => x => f(n(f)(x));
let add = m => n => n(succ)(m);

let pair_succ = p => pair(right(p))(succ(right(p)));
let prev = n => left(n(pair_succ)(pair(\$0)(\$0)));
let sub = m => n => n(prev)(m);

let len = l => when(isEmpty(l))
(_ => \$0)

let sum = l => when(isEmpty(l))
(_ => \$0)

let rcon = t => h => when(is_\$\$(h))
(_ => t)
(_ => rcon(con(h)(t)));

let rev = r => l => when(isEmpty(l))
(_ => r)

let reverse = l => rev(nil)(l);

let elems = rcon(nil);

let list = es => reverse(es(\$\$));

let map = l => f => when(isEmpty(l))
(_ => nil)

let lt = list(elems(\$1)(\$2)(\$3));
let lt2 = map(list(elems(\$1)(\$2)(\$3)))(elem => sub(elem)(\$1));

console.log(natural(len(lt)));
console.log(natural(sum(lt)));
console.log(array(lt2));

function natural(n) {
return n(i => i + 1)(0);
}

function array(lt) {
function arr(acc, l) {
return when(isEmpty(l))
(() => acc)