-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy path5kyu_ChurchBooleans.js
29 lines (21 loc) · 963 Bytes
/
5kyu_ChurchBooleans.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 5kyu - Church Booleans
// There are a few Katas about Church Numerals so let's talk about booleans.
// In lambda calculus, the only primitive are lambdas. No numbers, no strings, and of course no booleans. Everything is reduced to anonymous functions.
// Booleans are defined thusly (this definition is preloaded for you) :
// const True = T => F => T;
// const False = T => F => F;
// Your task will be to implement basic operators on booleans (using only lambdas and function application) : Not, And, Or and Xor.
// To help, the function unchurch comes preloaded, and returns the native boolean given a church boolean :
// unchurch(True); //true;
// Note: You should not use the following:
// numbers
// strings
// booleans
// boolean operators
// objects (curly brackets) or arrays (square brackets)
// regexp
// "new"
const Not = A => A(False)(True);
const And = A => B => A(B)(A);
const Or = A => B => A(A)(B);
const Xor = A => B => A(Not(B))(B);