Last active
August 5, 2019 08:42
-
-
Save joelnet/5f70e9d381c5d52bc006d04c6813780a to your computer and use it in GitHub Desktop.
Boolean Logic with the SKI Combinators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// S and K are primitive function combinators. | |
const S = a => b => c => a (c) (b (c)) | |
const K = a => b => a | |
// Non-primitive combinators can be created with S and K. | |
const C = S (S (K (S (K (S)) (K))) (S)) (K (K)) | |
const I = S (K) (K) | |
const KI = K (I) | |
const M = S (I) (I) | |
const R = S (K (S (K (S)) (K))) (S (K (S (I))) (K)) | |
// Friendly Names given to combinators for readability. | |
const True = K | |
const False = KI | |
const Or = M // a => b => a (a) (b) | |
const And = R (KI) // a => b => a (b) (a) | |
const Not = C | |
// /** | |
// * π₯π₯π₯ Boolean Logic π₯π₯π₯ | |
// */ | |
And (True) (True) ('π') ('π') //? | |
And (True) (False) ('π') ('π') //? | |
And (False) (True) ('π') ('π') //? | |
And (False) (False) ('π') ('π') //? | |
Or (True) (True) ('π') ('π') //? | |
Or (True) (False) ('π') ('π') //? | |
Or (False) (True) ('π') ('π') //? | |
Or (False) (False) ('π') ('π') //? | |
Not (True) ('π') ('π') //? | |
Not (False) ('π') ('π') //? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment