Enable λ-calculus within the TypeScript type system, thereby allowing combinatory-calculations and other combinators to be utilized.
The core logic code is here, less than 50 lines and provides an accurate implementation.
在 TypeScript 类型系统 中实现 λ-演算,支持 组合逻辑计算 及其他组合子的使用。
Do simple lambda-calculus
import { λ, reduce } from './src/index.ts'
type _flag_1_ = λ<() => [never]>
type _flag_2_ = λ<() => [never]>
type TRUE = λ<() => () => [0]>
type FALSE = λ<() => () => [1]>
type IFELSE = λ<() => () => () => [0, 1, 2]>
type result1 = reduce<[IFELSE, TRUE, _flag_1_, _flag_2_]> // equivalent to _flag_1_
type result2 = reduce<[IFELSE, FALSE, _flag_1_, _flag_2_]> // equivalent to _flag_2_
Moreover, you can perform combinator calculations.
import { C, TRUE, FALSE, reduce } from './src/index.ts'
// do SKI-combinator calculus
type NOT = C
type NOT_TRUE = reduce<[NOT, TRUE]> // equivalent to FALSE
type NOT_FALSE = reduce<[NOT, FALSE]> // equivalent to TRUE
// define my-own FALSE (SKI-based) - they are all equivalent
type MY_FALSE_1 = λ<() => () => [1]>
type MY_FALSE_2 = reduce<[K, I]>
type MY_FALSE_3 = reduce<[C, K]>
This project is licensed under the MIT License.