Created
July 22, 2016 06:06
-
-
Save viebel/d751d8dbd5cc3ee2707059dd028a811c to your computer and use it in GitHub Desktop.
Numbers in Lambda Calculus
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
(defn v [x] | |
(list 'λ x)) | |
(defn view [n] ((n v) 'x)) | |
(deftype LambdaNum [n] | |
Object | |
(toString [this] (str (view this))) | |
(equiv [this other] (-equiv this other)) | |
IPrintWithWriter | |
(-pr-writer [o writer _] (-write writer (view o))) | |
IEquiv | |
(-equiv [this other] | |
(if (instance? LambdaNum other) | |
(= (view this) (view other)) | |
false)) | |
IFn | |
(-invoke [this f] | |
(fn [x] | |
((apply comp (repeat n f)) x)))) | |
(def two (LambdaNum. 2)) | |
(def another-two (LambdaNum. (+ 1 1))) | |
(def zero (LambdaNum. 0)) | |
[zero | |
two | |
(str two) | |
(= two two) | |
(= two another-two) | |
(= two three)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment