Skip to content

Instantly share code, notes, and snippets.

@Boarders
Created September 12, 2019 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Boarders/99db42ead88d7252ff8555dd1fd35323 to your computer and use it in GitHub Desktop.
Save Boarders/99db42ead88d7252ff8555dd1fd35323 to your computer and use it in GitHub Desktop.
#lang scheme
;; church encoded zero
(define c-zero
(lambda (f x) x))
;; church encoded one
(define (add-1 cn)
(lambda (f x) (f (cn f x))))
;; addition of chruch numerals
(define (c-add cn cm)
(lambda (f x) (cn f (cm f x))))
;; mulitplication of church numerals
(define (c-mult cn cm)
(lambda (f x) (cn (lambda (x) (cm f x)) x)))
;; exponential of chrurch numerals
(define (c-exp cn cm)
(lambda (f x) (error "to do"))
;; convert from church numeral to literal
(define (to-Nat cn)
(cn add1 0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment