All Projects → terremoth → js-church-encoding

terremoth / js-church-encoding

Licence: GPL-3.0 license
Church Encoding Implementation in JavaScript

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to js-church-encoding

haskell-church-encodings
🌀 Church encodings written in Haskell
Stars: ✭ 23 (-30.3%)
Mutual labels:  encoding, church
guide.encode.moe
A guide for fansubbing
Stars: ✭ 123 (+272.73%)
Mutual labels:  encoding
Convertzz
繼承自convertz,但更好用的簡繁轉換工具
Stars: ✭ 181 (+448.48%)
Mutual labels:  encoding
Qs
Quick serialization of R objects
Stars: ✭ 225 (+581.82%)
Mutual labels:  encoding
Rust Lexical
Lexical, to- and from-string conversion routines.
Stars: ✭ 192 (+481.82%)
Mutual labels:  encoding
Iconv Lite
Convert character encodings in pure javascript.
Stars: ✭ 2,697 (+8072.73%)
Mutual labels:  encoding
Encoding
Encoding Standard
Stars: ✭ 176 (+433.33%)
Mutual labels:  encoding
StepULC
Efficient and single-steppable ULC evaluation algorithm
Stars: ✭ 15 (-54.55%)
Mutual labels:  lambda-calculus
ciphr
CLI crypto swiss-army knife for performing and composing encoding, decoding, encryption, decryption, hashing, and other various cryptographic operations on streams of data from the command line; mostly intended for ad hoc, infosec-related uses.
Stars: ✭ 100 (+203.03%)
Mutual labels:  encoding
Stego
🦕 stego is a steganographic swiss army knife.
Stars: ✭ 220 (+566.67%)
Mutual labels:  encoding
Go
decode/encode thrift message without IDL
Stars: ✭ 219 (+563.64%)
Mutual labels:  encoding
Encoding rs
A Gecko-oriented implementation of the Encoding Standard in Rust
Stars: ✭ 196 (+493.94%)
Mutual labels:  encoding
RCNB.js
Everything can be encoded into RCNB with JavaScript.
Stars: ✭ 50 (+51.52%)
Mutual labels:  encoding
Base X
Encode/decode any base
Stars: ✭ 191 (+478.79%)
Mutual labels:  encoding
OBS Settings Manager
Backup your OBS Studio profiles and manage them in an easy, user friendly way.
Stars: ✭ 20 (-39.39%)
Mutual labels:  encoding
Libchef
🍀 c++ standalone header-only basic library. || c++头文件实现无第三方依赖基础库
Stars: ✭ 178 (+439.39%)
Mutual labels:  encoding
Elixir Json
Native JSON library for Elixir
Stars: ✭ 216 (+554.55%)
Mutual labels:  encoding
Armor
Armor is a simple Bash script designed to create encrypted macOS payloads capable of evading antivirus scanners.
Stars: ✭ 228 (+590.91%)
Mutual labels:  encoding
BOHM1.1
Bologna Optimal Higher-Order Machine, Version 1.1
Stars: ✭ 45 (+36.36%)
Mutual labels:  lambda-calculus
apostello
sms for your church
Stars: ✭ 62 (+87.88%)
Mutual labels:  church

js-church-encoding

Church Encoding Implementation in JavaScript

// Unchurch
const decodeNumber  = a => a(b => b + 1)(0)
const decodeBoolean = a => a(true)(false)

// Numbers
const zero  = f => x => x
const one   = f => x => f(x)
const two   = f => x => f(f(x))
const three = f => x => f(f(f(x)))
const four  = f => x => f(f(f(f(x))))
const five  = f => x => f(f(f(f(f(x)))))
const six   = f => x => f(f(f(f(f(f(x))))))
const seven = f => x => f(f(f(f(f(f(f(x)))))))
const eight = f => x => f(f(f(f(f(f(f(f(x))))))))
const nine  = f => x => f(f(f(f(f(f(f(f(f(x)))))))))
const ten   = f => x => f(f(f(f(f(f(f(f(f(f(x))))))))))

// Operations
const succ = n => f => x => f(n(f)(x))
const pred = n => f => x => n( g => h => h(g(f)) )(u => x)(u => u)

// Math Operations
const add = m => n => f => x => m(f)(n(f)(x))
const sub = m => n => (n(pred))(m)
const mul = m => n => f => m(n(f))
const exp = m => n => n(m)
// Throws Uncaught RangeError: Maximum call stack size exceeded:
const div = n => ((f => (x =>x (x)) (x => f(x(x))))( c => n => m => f => x => (d => (n => n( x => (a => b => b))(a => b => a))(d)((f => x => x)(f)(x)) (f(c(d)(m)(f)(x))))((m => n => n(n => f => x => n(g => h => h(g(f)))(u => x)(u => u))(m))(n)(m) )))((n => f => x => f(n(f)(x)))(n))

// Booleans
const True  = a => b => a
const False = a => b => b

const And = p => q => p(q)(p)
const Or  = p => q => p(p)(q)
const Not = p => p(a => b => b)(a => b => a)
const Xor = a => b => a(Not(b))(b)
const If  = p => a => b => p(a)(b)

// Predicates
const isZero = n => n(x => False)(True)
const lessEq = m => n => isZero(sub(m)(n))
const eq = m => n => And(lessEq(m)(n))(lessEq(n)(m))

// Church Pairs
const pair   = x => y => z => z(x)(y)
const first  = p => p( x => y => x )
const second = p => p( x => y => y )

// Church Pair list encodings
const nil    = pair(True)(True)
const isNil  = first
const cons   = h => t => pair(False(pair(h)(t)))
const head   = z => first(second(z))
const tail   = z => second(second(z))

// Combinators
const S = x => y => z => x(z)(y(z))
const K = x => y => x
const I = x => x
const Y = f => x => f(v => x(x)(v))(x => f(v => x(x)(v)))
const U = f => f(f)
const B = S => (K(S))(K)
const C = S => (B(B)(S))(K(K))
const V = x => y => z => z(x)(y);

// General Math use without combinators, reductions or raw lambda
const Fib = rec => n => If(lessEq(n)(one))(one)(x => add(rec(sub(n)(one)))(rec(sub(n)(two)))(x))
const Fac = n => If(isZero(n))(_ => one)(mul(n)(Fac(pred(n))))
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].