• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-cqtcocoa誰得pythonphprubygameguibathyscaphec翻訳計画中(planning stage)omegatframeworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

A categorical programming language


Commit MetaInfo

修订版e9a1a66d26b0aeacf0a55d35aaf9dd91ed89021c (tree)
时间2022-03-15 10:33:03
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Add a tool for graphing hives.

更改概述

差异

--- /dev/null
+++ b/cammy-rpy/comb.nix
@@ -0,0 +1,4 @@
1+let
2+ makeBuilder = import ./builder.nix;
3+in
4+ makeBuilder ./comb.py "cammy-comb" false
--- /dev/null
+++ b/cammy-rpy/comb.py
@@ -0,0 +1,44 @@
1+import os
2+import sys
3+
4+from cammylib.hive import Hive
5+from cammylib.sexp import BASIS_ATOMS, BASIS_FUNCTORS
6+
7+def comb(dag):
8+ rv = {}
9+ for k, v in dag.iteritems():
10+ rv[k] = [x for x in v
11+ if x not in BASIS_ATOMS and x not in BASIS_FUNCTORS]
12+ return rv
13+
14+def dot(graph):
15+ rv = ["digraph {"]
16+ for k, vs in graph.iteritems():
17+ for v in vs:
18+ rv.append('"%s" -> "%s";' % (k, v))
19+ rv.append("}")
20+ return "\n".join(rv)
21+
22+def main(argv):
23+ hivepath = argv[-1]
24+ hive = Hive(hivepath)
25+ prefix = len(hivepath)
26+ for dirpath, dirnames, filenames in os.walk(hivepath):
27+ for filename in filenames:
28+ if not filename.endswith(".cammy"):
29+ continue
30+ fullpath = os.path.join(dirpath, filename)
31+ suffix = len(fullpath) - 6
32+ assert suffix >= 0, "proven by .endswith() check above"
33+ atom = fullpath[prefix:suffix]
34+ hive.load(atom)
35+ graph = comb(hive.dag)
36+ print dot(graph)
37+ return 0
38+
39+def target(driver, *args):
40+ driver.exe_name = "cammy-comb"
41+ return main, None
42+
43+if __name__ == "__main__":
44+ main(sys.argv)
--- /dev/null
+++ b/hive/double/from-pair.cammy
@@ -0,0 +1,7 @@
1+(fun/apppair
2+ (comp snd (comp either (case (fun/name left) (fun/name right))))
3+ fst)
4+
5+Convert a pair into a double, where the first component of the pair is the
6+element to embed and the second component is a Boolean tag indicating which
7+side of the sum to occupy.
--- /dev/null
+++ b/hive/double/to-pair.cammy
@@ -0,0 +1,4 @@
1+(case (pair id (fun/const t)) (pair id (fun/const f)))
2+
3+Convert a double value to a pair containing a Boolean tag indicating which
4+side of the double the value occupies.
--- a/hive/fractal-membership.cammy
+++ b/hive/fractal-membership.cammy
@@ -1,7 +1,7 @@
11 (comp
22 (iter-fractal @0 @1)
33 (comp
4- (list/filter (f/ltpair v2/norm (fun/const f/2)))
4+ (list/filter v2/c-mag-2)
55 (comp list/len
66 (f/divpair nat/to-f (fun/const (comp @1 nat/to-f))))))
77
--- /dev/null
+++ b/hive/fun/distribr.cammy
@@ -0,0 +1,6 @@
1+(comp
2+ (comp fun/swap fun/distribl)
3+ (case (comp fun/swap left) (comp fun/swap right)))
4+
5+Distribute to the right.
6+
--- a/hive/fun/int-comp.cammy
+++ b/hive/fun/int-comp.cammy
@@ -1 +1,3 @@
11 (curry (comp (comp fun/assr (pair fst (comp snd fun/app))) fun/app))
2+
3+An internalized version of composition.
--- /dev/null
+++ b/hive/fun/iter-maybe.cammy
@@ -0,0 +1,5 @@
1+(pr
2+ (fun/name monads/maybe/unit)
3+ (comp (pair id (fun/const (fun/name @0))) monads/maybe/int-comp))
4+
5+Iterate a given arrow up to zero or more times.
--- /dev/null
+++ b/hive/monads/maybe/int-comp.cammy
@@ -0,0 +1,7 @@
1+(curry
2+ (comp
3+ (comp fun/assr (pair fst (comp snd fun/app)))
4+ (comp fun/distribr (case fun/app (comp ignore right)))))
5+
6+An internalized version of composition in the Kleisli category for the maybe
7+monad.
--- /dev/null
+++ b/hive/square/from-pair.cammy
@@ -0,0 +1,3 @@
1+(curry (comp fun/swap bool/pick))
2+
3+Convert a pair to a square.
--- /dev/null
+++ b/hive/square/to-pair.cammy
@@ -0,0 +1,3 @@
1+(pair (fun/apppair id (fun/const t)) (fun/apppair id (fun/const f)))
2+
3+Convert a square to a pair.
--- /dev/null
+++ b/hive/sum/mapleft.cammy
@@ -0,0 +1,3 @@
1+(case (comp @0 left) right)
2+
3+Map over the left-hand case of a sum.
--- /dev/null
+++ b/hive/sum/mapright.cammy
@@ -0,0 +1,4 @@
1+(case left (comp @0 right))
2+
3+Map over the right-hand case of a sum.
4+
--- /dev/null
+++ b/hive/v2/c-mag-2.cammy
@@ -0,0 +1,3 @@
1+(f/ltpair v2/norm (fun/const f/2))
2+
3+Whether a complex number's magnitude is less than 2.
--- a/todo.txt
+++ b/todo.txt
@@ -3,12 +3,14 @@
33 * : commands
44 * help, describe commands
55 * edit an atom's trail
6-* list/eq : [X × X, 2] → [[X] × [X], 2]
7-* list/zip : [X] × [Y] → [X × Y]
8-* list/tail : [X] → [X]
6+* More list manipulations
7+ * list/eq : [X × X, 2] → [[X] × [X], 2]
8+ * list/zip : [X] × [Y] → [X × Y]
9+ * list/tail : [X] → [X]
910 * rat
1011 * refactoring from the bikeshed: ignore -> !
1112 * Might not be important since fun/const is the only user!
13+ * zero -> 0, f-zero -> f-0, f-one -> f-1 maybe?
1214 * Transcendental and other constants
1315 * Euler's constant e
1416 * Euler's constant gamma
@@ -30,6 +32,8 @@
3032 * Cantor's type of bitstrings: N -> 2
3133 * The square type: For a type X, 2 -> X
3234 * Another special case of reader monad
35+ * There's an equivalence X x X <-> [2, X]
36+ * Done?
3337 * Moore machines: For state type Q and input type S, Q × S -> Q
3438 * Moore transducers: [Q × S, Q] -> [Q × S, Q]
3539 * Mealy machines: For state type Q, input type S, and output type L, Q × S -> Q × L
@@ -48,3 +52,7 @@
4852 * Maybe allow inductive datatype definitions during toolchain build time
4953 * Start by factoring out N and lists into inductive datatype modules somehow
5054 * Then add trees, etc.
55+* Faster fractals are nearly here
56+ * We now can iter-maybe, short-circuiting evaluation
57+ * We need to iter-maybe but also keep track of how many steps were taken
58+ * Instead of X -> [N, Y + 1], we need X -> [N, N x (Y + 1)]