A categorical programming language
Revision | 0f8f6b6e68ec2579b9b1a4381812864e9ab6e713 (tree) |
---|---|
Time | 2023-01-25 02:01:07 |
Author | Corbin <cds@corb...> |
Commiter | Corbin |
Evaluate images and preimages directly.
I've gotta figure out how to extract the results decently, but this is
amazing in general. The one thing I don't like is that 1 is in the image
of (comp succ succ), which suggests that succ° is broken somehow.
@@ -59,13 +59,22 @@ | ||
59 | 59 | (define (cammy-image expr) |
60 | 60 | (time |
61 | 61 | (display |
62 | - (map | |
62 | + ; (map | |
63 | 63 | ; need the type to display the value properly |
64 | - (lambda (q) (elt->str (car q) (cdr q))) | |
64 | + ; (lambda (q) (elt->str (car q) (cdr q))) | |
65 | 65 | (run 10 (q) (fresh (s t i o) |
66 | 66 | ; package them up here |
67 | 67 | (conso t o q) |
68 | - (cammy° expr s t) (eval° expr i o))))) | |
68 | + (cammy° expr s t) (eval° expr i o)))) | |
69 | + (newline))) | |
70 | + | |
71 | +(define (cammy-preimage expr) | |
72 | + (time | |
73 | + (display | |
74 | + (run 10 (q) (fresh (s t i o) | |
75 | + ; package them up here | |
76 | + (conso s i q) | |
77 | + (cammy° expr s t) (eval° expr i o)))) | |
69 | 78 | (newline))) |
70 | 79 | |
71 | 80 | (define (repl!) |
@@ -76,6 +85,7 @@ | ||
76 | 85 | ; command? |
77 | 86 | ['? (display "help goes here?") (newline) (repl!)] |
78 | 87 | ['image (cammy-image (read)) (repl!)] |
88 | + ['preimage (cammy-preimage (read)) (repl!)] | |
79 | 89 | ; read |
80 | 90 | [expr |
81 | 91 | (if (eof-object? expr) |
@@ -170,11 +170,18 @@ | ||
170 | 170 | (conde |
171 | 171 | ((== expr 'id) (== i o)) |
172 | 172 | ((fresh (f g u) (== expr `(comp ,f ,g)) (eval° f i u) (eval° g u o))) |
173 | + ((== expr 'ignore) (== o 'star)) | |
173 | 174 | ((== expr 'fst) (caro i o)) |
174 | 175 | ((== expr 'snd) (cdro i o)) |
175 | 176 | ((== expr 'dup) (conso i i o)) |
177 | + ((== expr 't) (== i 'star) (== o #t)) | |
178 | + ((== expr 'f) (== i 'star) (== o #f)) | |
176 | 179 | ((== expr 'not) (not° i o)) |
177 | 180 | ((== expr 'zero) (== i 'star) (zeroo o)) |
178 | 181 | ((== expr 'succ) (succ° i o)) |
182 | + ((fresh (f g n) (== expr `(pr ,f ,g)) | |
183 | + (conde | |
184 | + ((zeroo i) (eval° f 'star o)) | |
185 | + ((succ° n i) (eval° `(comp ,expr ,g) n o))))) | |
179 | 186 | )) |
180 | 187 | ) |