# 笔记: 关于 SKI 组合子及其实现

A function or definition with no free variables.

1924 苏联人发现的 SKI, 后来 Haskell Curry 的版本是 BCKW:
https://esolangs.org/wiki/Com...

``````S f g x = f x (g x);
K x y = x;
I x = x;``````

``````S = λx.λy.λz.(xz)(yz)
K = λx.λy.x
I = λx.x``````

``S K K x = I x = x``

``````B x y z = x (y z);
C x y z = x z y;
K x y = x;
W x y = x y y;``````

https://stackoverflow.com/que...

https://gist.github.com/Avaq/...

Fun with Combinators: https://doisinkidney.com/post...

https://en.wikipedia.org/wiki...
lambda 表达式都是可以转化为 SK 组合子的表达式的,

"An Introduction to Combinator Compilers and Graph Reduction Machines" by David Graunke

Wolfram 的演讲视频, 中间涉及到很多 Combinators, 包括 SKI 原作者的历史
"Combinators: A 100-Year Celebration"

### 代码实现

https://github.com/ngzhian/ski

https://crypto.stanford.edu/~...

``````true = \x y -> x
false = \x y -> y
0 = \f x -> x
1 = \f x -> f x
succ = \n f x -> f(n f x)
pred = \n f x -> n(\g h -> h (g f)) (\u -> x) (\u ->u)
mul = \m n f -> m(n f)
is0 = \n -> n (\x -> false) true
Y = \f -> (\x -> x x)(\x -> f(x x))
fact = Y(\f n -> (is0 n) 1 (mul n (f (pred n))))
main = fact (succ (succ (succ 1)))  -- Compute 4!``````

``s(k(s(skk)(skk)))(s(k(ss(k(s(skk)(skk)))))k)(s(k(s(k(s(s(s(s(skk)(k(k(sk))))(kk))(sk))))(s(s(ks)k))))(s(k(ss(k(s(k(s(k(s(k(ss(k(sk))))))(s(k(s(k(ss(kk)))k)))))(s(k(ss(k(s(k(s(k(s(k(s(k(s(skk)))k))))(s(skk))))k))))k)))))k))(s(s(ks)k)(s(s(ks)k)(s(s(ks)k)(skk))))uz``

unlambda 是一门很早的基于 SK(I) 组合子实现的语言,

https://medium.com/@marinalim...

http://augustss.blogspot.com/...
`if cond t-branch f-branch` 普通函数的版本, 所有参数都被求值的,

lambda calculus 和组合子这种数学化的表示, 应该也是对应 lazy 的版本.

### 其他

Combinatory Logic: From Philosophy and Mathematics to Computer Science

Combinator 在 JavaScript 提供抽象能力的一些展示.
https://codeburst.io/combinat...

https://www.ioccc.org/2012/tr...

##### 题叶
ClojureScript 爱好者.
##### 题叶

ClojureScript 爱好者.

17.2k 声望
2.6k 粉丝