JSFiddle - React, Tailwind, and code Playground

by Phuwadon Verasertniyom

HTML

<!DOCTYPE html>
<html>
<body>
<h1>Please open console</h1>
</body>
</html>

JavaScript

const TRUE = a => b => a;
const FALSE = a => b => b;
const NOT = a => a(b => c => c)(b => c => b);
const AND = a => b => a(b)(a);
const OR = a => b => b(b)(a);
const ZERO = a => b => b;
const IS_ZERO = a => a(b => c => d => d)(b => c => b);
const SUCC = a => b => c => b(a(b)(c))
const PRED = a => b => c => a(d => e => e(d(b)))(d => c)(d => d);
const PLUS = a => b => c => d => a(c)(b(c)(d));
const MULT = a => b => c => a(b(c));
const COMPOSE = a => b => c => a(b(c))
const IF = a => b => c => a(b)(c)
const NIL = a => b => b;
const IS_NIL = a => a(b => c => d => e => e)(b => c => b);
const CONS = a => b => c => d => c(a)(b(c)(d));
const HEAD = a => a(b => c => b)(b => c => c);
const TAIL = a => b => c => a(d => e => f => f(d)(e(b)))(d => c)(d => e => e);
/* const Y = a => (b => a(b(b)))(b => a(b(b))); */
const Z = a => (b => a(c => b(b)(c)))(b => a(c => b(b)(c)));

const value = a => ({
  as: b => {
    switch (b) {
      case 'boolean':
        return a(true)(false);
      case 'number':
        return a(b => b + 1)(0);
      default: {
        if (b.startsWith('list')) {
          const types = b.substring(5, b.length - 1).split(',');
          const toArray = c => d => IS_NIL(d)(true)(false) ?
            [] :
            [value(HEAD(d)).as(types[c]), ...toArray(types.length === 1 ? 0 : c + 1)(TAIL(d))];
          return toArray(0)(a);
        }
      }
    }
  }
});

console.clear();

console.group('Boolean');
console.log('TRUE: ', value(TRUE).as('boolean'));
console.log('FALSE: ', value(FALSE).as('boolean'));
console.groupEnd();

console.group('Not');
console.log('NOT TRUE: ', value(NOT(TRUE)).as('boolean'));
console.log('NOT FALSE: ', value(NOT(FALSE)).as('boolean'));
console.groupEnd();

console.group('And');
console.log('AND TRUE TRUE: ', value(AND(TRUE)(TRUE)).as('boolean'));
console.log('AND TRUE FALSE: ', value(AND(TRUE)(FALSE)).as('boolean'));
console.log('AND FALSE TRUE: ', value(AND(FALSE)(TRUE)).as('boolean'));
console.log('AND FALSE FALSE: ',...