A categorical programming language
修订版 | 609bc590fff8bb6e9a6a24e3426c943d9937c5ef (tree) |
---|---|
时间 | 2022-03-10 12:09:04 |
作者 | Corbin <cds@corb...> |
Commiter | Corbin |
Decide on the order of lists and fix fold.
@@ -300,6 +300,9 @@ class PrimRec(Arrow): | ||
300 | 300 | cs.unify(fdom, fcod) |
301 | 301 | return cs.concrete("N"), fcod |
302 | 302 | |
303 | +# NB: Lists are built from left-to-right; [0, 1] is | |
304 | +# (cons 1 (cons 0 nil)) | |
305 | + | |
303 | 306 | class Nil(Arrow): |
304 | 307 | _immutable_ = True |
305 | 308 | def run(self, x): return Xs([]) |
@@ -308,7 +311,7 @@ class Nil(Arrow): | ||
308 | 311 | |
309 | 312 | class Cons(Arrow): |
310 | 313 | _immutable_ = True |
311 | - def run(self, x): return Xs([x.first()] + x.second().l()) | |
314 | + def run(self, x): return Xs(x.second().l() + [x.first()]) | |
312 | 315 | def types(self, cs): |
313 | 316 | x = cs.fresh() |
314 | 317 | xs = cs.functor("list", [x]) |
@@ -1 +1,3 @@ | ||
1 | -(comp (pair @0 @1) fun/app) | |
1 | +(pair/of fun/app @0 @1) | |
2 | + | |
3 | +Apply the output of one arrow onto the output of another. |
@@ -0,0 +1,4 @@ | ||
1 | +(pair/of cons @0 @1) | |
2 | + | |
3 | +Build a list whose head is the output of one arrow and whose tail is the | |
4 | +output of another arrow. |
@@ -0,0 +1,6 @@ | ||
1 | +(uncurry (fold (fun/name id) | |
2 | + (curry (fun/apppair | |
3 | + (comp fst snd) | |
4 | + (list/conspair (comp fst fst) snd))))) | |
5 | + | |
6 | +Reverse a list onto an input suffix. |
@@ -0,0 +1,3 @@ | ||
1 | +(comp (pair id (fun/const nil)) list/reverse-onto) | |
2 | + | |
3 | +Reverse a list in linear time. |
@@ -0,0 +1,3 @@ | ||
1 | +(comp (pair id (fun/const nil)) cons) | |
2 | + | |
3 | +A list with only one value. |
@@ -0,0 +1,3 @@ | ||
1 | +(curry (comp fun/app not)) | |
2 | + | |
3 | +The complement of a subobject. |
@@ -0,0 +1,7 @@ | ||
1 | +(curry (comp | |
2 | + (pair | |
3 | + (fun/apppair (comp fst fst) snd) | |
4 | + (fun/apppair (comp fst snd) snd)) | |
5 | + conj)) | |
6 | + | |
7 | +The intersection of two subobjects. |
@@ -0,0 +1,7 @@ | ||
1 | +(curry (comp | |
2 | + (pair | |
3 | + (fun/apppair (comp fst fst) snd) | |
4 | + (fun/apppair (comp fst snd) snd)) | |
5 | + disj)) | |
6 | + | |
7 | +The union of two subobjects. |
@@ -0,0 +1,3 @@ | ||
1 | +(fun/const f) | |
2 | + | |
3 | +An empty subobject. |
@@ -0,0 +1,3 @@ | ||
1 | +(fun/const t) | |
2 | + | |
3 | +A subobject that is just the original object. |