Created
July 4, 2017 13:28
-
-
Save dz1984/bf650bca03d49f441506a8ba36c102ce to your computer and use it in GitHub Desktop.
Using Racket to implement operators in the lambda calculus for Church number.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define zero | |
(lambda (f) | |
(lambda (x) x))) | |
(define (add-1 n) | |
(lambda (f) | |
(lambda(x) (f ((n f) x))))) | |
(define one | |
(lambda (f) | |
(lambda (x) (f x)))) | |
(define two | |
(lambda (f) | |
(lambda (x) (f (f x))))) | |
(define three | |
(lambda (f) | |
(lambda (x) (f (f (f x)))))) | |
(define ((plus m) n) | |
(lambda (f) | |
(lambda (x) | |
((n f) ((m f) x))))) | |
(define (display-church-number n) | |
(display "λfλx.") | |
(display ((n (lambda (x) (cons "f" x))) "x")) | |
(newline)) | |
(display-church-number zero) | |
(display-church-number one) | |
(display-church-number (add-1 zero)) | |
(display-church-number two) | |
(display-church-number (add-1 one)) | |
(display-church-number three) | |
(display-church-number (add-1 two)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment