A categorical programming language
Revision | 94316419d77d60a26f67487754df350dfc1a0290 (tree) |
---|---|
Zeit | 2024-06-30 10:09:30 |
Autor | Corbin <cds@corb...> |
Commiter | Corbin |
Add a sort of Maxwell's-laws presentation.
I don't personally put much stock in this sort of thing, but Alan Kay
and Douglas Crockford think it's essential.
@@ -0,0 +1,13 @@ | ||
1 | +(define (id x) x) (define ((comp f g) x) (g (f x))) (define (ignore _) '1) | |
2 | +(define ((pair f g) x) (cons (f x) (g x))) (define fst car) (define snd cdr) | |
3 | +(define ((cas f g) x) ((if (car x) f g) (cdr x))) | |
4 | +(define (left x) (cons #t x)) (define ((right x)) (cons #f x)) | |
5 | +(define (t _) #t) (define (f _) #f) (define (either b) (cons b '1)) | |
6 | +(define (conj x) (and (car x) (cdr x))) (define (disj x) (or (car x) (cdr x))) | |
7 | +(define (((curry f) x) y) (f (cons x y))) | |
8 | +(define ((uncurry f) p) ((f (car p)) (cdr p))) | |
9 | +(define (zero _) 0) (define (succ x) (+ 1 x)) | |
10 | +(define ((pr x f) n) (if (zero? n) (x '1) (f ((pr x f) (- n 1))))) | |
11 | +(define (nil _) '()) (define con id) | |
12 | +(define ((fold x f) l) | |
13 | + (if (null? l) (x '1) (f (cons (car l) ((fold x f) (cdr l)))))) |