Skip to content

Instantly share code, notes, and snippets.

@gatlin
Created January 21, 2014 17:23
Show Gist options
  • Save gatlin/8544237 to your computer and use it in GitHub Desktop.
Save gatlin/8544237 to your computer and use it in GitHub Desktop.
(define add (λ (n)
(λ (m)
(λ (f)
(λ (x)
((n f) ((m f) x)))))))
(define mult (λ (n)
(λ (m)
(λ (f)
(n (m f))))))
(define (church->number n)
((n add1) 0))
; These two definitions of `one` are equivalent. Why?
(define one-manual (λ (f)
(λ (x)
(f x))))
(define one-computed (succ zero))
; zero is a function
(define zero (λ (f)
(λ (x)
x)))
; succ ("successor") is also a function
(define succ (λ (n)
(λ (f)
(λ (x)
(f ((n f) x))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment