March 26th Monday (三月  二十六日 月曜日)

(define (f x) (cons 'x x))

(define (zero f)
  (lambda (x)
    x))

(define (one f)
  (lambda (x)
    (f x)))

(define (two f)
  (lambda (x)
    (f (f x))))

(define (three f)
  (lambda (x)
    (f (f (f x)))))

(define (add-one n)
  (lambda (f)
    (lambda (x)
      (f ((n f) x)))))

(define (add a b)
  (lambda (f)
    (lambda (x)
      ((a f) ((b f) x)))))

(define (mul a b)
  (lambda (f) (lambda (x) ((a (b f)) x))))

  The above list are all Church Numbers.  Yes, it is so famous.  At the begin of learning them, I
was confused.  Having gong over the comprehension I found it is so simple.  I thought I know how
to Church invent those interesting numbers.  In fact, he just found it.

  Let's look at "one", "two", "three", and "zero".  As a matter of fact, those numbers all are
high order operators.  That is to say, they like "map", "for-each", they take a function and one
parameter.  What is the discrepancy between "map" and them?  Look inside of them!

  The "zero" is just return its argument and not call the function taken; the "one" just call its
function to its argument taken one time; the "two" call the function to its argument only two
times.  From them, we know a new way to counter -- composing a function with a parameter.

  ((two f) 'z) => (x x . 'z)

  So, the "add-one" is also simple.  Firstly, let's look at the above statement how to use "two".
The "(two f)" is the key to understand "add-one", "add".  The "((n f) x)" is alike the "((two f) 'z)".
Yes, it will compose "f" with "x".  Finally, compose "f" again.  In other words, call "f" with a result
returned from "((n f) x)".   Now the "add" is easy to understand!  Having composing "f" "b" times with "x",
call the result function from "(a f)" with result returned from "((b f) x)".

  Now we know it is so important for Church numbers or related operators to make a correct composite
function.  So, the "mul" is also not hard to understand.  The "(two f)" will make a composite function
like "(f (f (f ...)))".  The "(a (b f))" is mean to compose "f" "(a - 1) * (b - 1)" times.  For example,
if "a" is three and "b" is two, the number of composing "f" is (3-1) * (2-1) = 2.  "(f (f ...))" resulted
from "(two f)", "(p (p (p ...)" resulted from "(three p)".  Having substituted "(f (f ...))" for "p".  The
final composite result is "(f (f (f (f (f (f ...))))))".  OK, our goal reached at. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值