A categorical programming language
修订版 | 90d9bc9042fe04d7cc376d16dfb049446b5031d9 (tree) |
---|---|
时间 | 2022-03-12 23:26:47 |
作者 | Corbin <cds@corb...> |
Commiter | Corbin |
Build a DAG while loading expressions into a hive.
@@ -16,6 +16,7 @@ class Hive(object): | ||
16 | 16 | def __init__(self, hivepath): |
17 | 17 | self.hivepath = hivepath |
18 | 18 | self.exprs = {} |
19 | + self.dag = {} | |
19 | 20 | |
20 | 21 | def load(self, atom): |
21 | 22 | if atom in self.exprs: |
@@ -27,6 +28,9 @@ class Hive(object): | ||
27 | 28 | try: |
28 | 29 | with open(fullpath, "r") as handle: |
29 | 30 | sexp, trail = parse(handle.read()) |
31 | + symbols = {} | |
32 | + sexp.symbols(symbols) | |
33 | + self.dag[atom] = symbols | |
30 | 34 | sexp = sexp.canonicalize(self) |
31 | 35 | self.exprs[atom] = sexp |
32 | 36 | # print("Loaded", atom, sexp) |
@@ -27,6 +27,9 @@ class Atom(SExp): | ||
27 | 27 | def asStr(self): |
28 | 28 | return self.symbol |
29 | 29 | |
30 | + def symbols(self, s): | |
31 | + s[self.symbol] = None | |
32 | + | |
30 | 33 | def substitute(self, args): |
31 | 34 | return self |
32 | 35 |
@@ -65,6 +68,11 @@ class Functor(SExp): | ||
65 | 68 | args = " ".join([arg.asStr() for arg in self.arguments]) |
66 | 69 | return "(%s %s)" % (self.constructor, args) |
67 | 70 | |
71 | + def symbols(self, s): | |
72 | + s[self.constructor] = None | |
73 | + for arg in self.arguments: | |
74 | + arg.symbols(s) | |
75 | + | |
68 | 76 | def substitute(self, args): |
69 | 77 | return Functor(self.constructor, |
70 | 78 | [arg.substitute(args) for arg in self.arguments]) |
@@ -120,6 +128,9 @@ class Hole(SExp): | ||
120 | 128 | def asStr(self): |
121 | 129 | return "@%d" % self.index |
122 | 130 | |
131 | + def symbols(self, s): | |
132 | + pass | |
133 | + | |
123 | 134 | def substitute(self, args): |
124 | 135 | return args[self.index] |
125 | 136 |
@@ -3,6 +3,7 @@ let | ||
3 | 3 | inherit (nixpkgs) pkgs; |
4 | 4 | jelly = (import jelly/Cargo.nix { pkgs = nixpkgs; }).rootCrate.build; |
5 | 5 | movelist = import ./movelist { inherit nixpkgs; }; |
6 | + cammy-comb = import ./cammy-rpy/comb.nix { inherit nixpkgs jelly; }; | |
6 | 7 | cammy-draw = import ./cammy-rpy/draw.nix { inherit nixpkgs jelly; }; |
7 | 8 | cammy-frame = import ./cammy-rpy/frame.nix { inherit nixpkgs jelly; }; |
8 | 9 | cammy-repl = import ./cammy-rpy/repl.nix { inherit nixpkgs jelly; }; |
@@ -25,6 +26,7 @@ in pkgs.stdenv.mkDerivation { | ||
25 | 26 | makeWrapper ${jelly}/bin/jelly $out/bin/cammy-jelly |
26 | 27 | |
27 | 28 | # RPython tools |
29 | + makeWrapper ${cammy-comb}/bin/cammy-comb $out/bin/cammy-comb | |
28 | 30 | makeWrapper ${cammy-draw}/bin/cammy-draw $out/bin/cammy-draw |
29 | 31 | makeWrapper ${cammy-frame}/bin/cammy-frame $out/bin/cammy-frame |
30 | 32 | makeWrapper ${cammy-repl}/bin/cammy-repl $out/bin/cammy-repl |
@@ -0,0 +1,3 @@ | ||
1 | +(comp either (case (fun/name @0) (fun/name @1))) | |
2 | + | |
3 | +As close as we can get to an if-expression. |
@@ -1 +1,3 @@ | ||
1 | 1 | (pr (fun/name id) (comp (pair id (fun/const (fun/name @0))) fun/int-comp)) |
2 | + | |
3 | +Iterate a given arrow zero or more times. |
@@ -0,0 +1,3 @@ | ||
1 | +(fun/flip (comp (pair (fun/const (fun/name @0)) (fun/iter @1)) fun/int-comp)) | |
2 | + | |
3 | +Observe the value of an endomorphism after a specified number of iterations. |
@@ -0,0 +1,3 @@ | ||
1 | +(comp (pair/mapfst list/reverse) list/reverse-onto) | |
2 | + | |
3 | +Concatenate two lists into a single list. |
@@ -0,0 +1,3 @@ | ||
1 | +(fold nil (comp (pair fst cons) cons)) | |
2 | + | |
3 | +Repeat each value in a list twice. |
@@ -0,0 +1,3 @@ | ||
1 | +(pr zero (comp succ succ)) | |
2 | + | |
3 | +Double a natural number by counting every successor operation twice. |
@@ -1 +1,3 @@ | ||
1 | 1 | (comp fun/dup nat/add) |
2 | + | |
3 | +Double a natural number by adding it to itself. |
@@ -0,0 +1,8 @@ | ||
1 | +(pr | |
2 | + (pair zero f) | |
3 | + (fun/apppair | |
4 | + (comp snd (bool/if (pair succ (fun/const f)) (pair id (fun/const t)))) | |
5 | + fst)) | |
6 | + | |
7 | +Shift all of the bits in a natural number towards the least-significant bit. | |
8 | +The least-significant bit itself is also returned. |
@@ -0,0 +1,3 @@ | ||
1 | +(pair (comp fst @0) snd) | |
2 | + | |
3 | +Map over the first component of a pair. |
@@ -0,0 +1,3 @@ | ||
1 | +(pair fst (comp snd @0)) | |
2 | + | |
3 | +Map over the second component of a pair. |
@@ -14,7 +14,9 @@ in pkgs.stdenv.mkDerivation { | ||
14 | 14 | egg2nix |
15 | 15 | # maintaining cammy-rpy/ |
16 | 16 | pythonPackages.pyflakes |
17 | - # developing cammy-weave | |
17 | + # using cammy-comb | |
18 | + graphviz | |
19 | + # using cammy-weave | |
18 | 20 | pandoc texlive.combined.scheme-small |
19 | 21 | # using cammy-repl |
20 | 22 | rlwrap |
@@ -6,7 +6,6 @@ | ||
6 | 6 | * list/eq : [X × X, 2] → [[X] × [X], 2] |
7 | 7 | * list/zip : [X] × [Y] → [X × Y] |
8 | 8 | * list/tail : [X] → [X] |
9 | -* list/append : [X] × [X] → [X] | |
10 | 9 | * rat |
11 | 10 | * refactoring from the bikeshed: ignore -> ! |
12 | 11 | * Might not be important since fun/const is the only user! |
@@ -43,11 +42,9 @@ | ||
43 | 42 | * X -> X: should be id? |
44 | 43 | * X -> 1: should be ignore |
45 | 44 | * 1 -> 2: should be t or f |
46 | -* New int type | |
47 | - * Current type: quotient of N × N under subtraction | |
48 | - * big, tricky case analysis, big quotient overlap | |
49 | - * Proposed type: quotient of N + N gluing zero | |
50 | - * almost minimal, sign bit, quotient glues exactly two elements into one | |
51 | 45 | * Refactoring tools |
52 | 46 | * Find all leaves in a hive |
53 | 47 | * Rename an expression and change all callers |
48 | +* Maybe allow inductive datatype definitions during toolchain build time | |
49 | + * Start by factoring out N and lists into inductive datatype modules somehow | |
50 | + * Then add trees, etc. |