A categorical programming language
修訂 | d33882093f56758a151388896270bd7cb62539f3 (tree) |
---|---|
時間 | 2023-01-14 09:06:27 |
作者 | Corbin <cds@corb...> |
Commiter | Corbin |
Optimize dissolved expressions, always.
Similar to the old logic, but now that I have a REPL again, I can
quickly iterate.
@@ -242,8 +242,12 @@ def dissolveNewExpression(): | ||
242 | 242 | if isTemplate(expr): |
243 | 243 | print("can't handle templates yet") |
244 | 244 | abort(500) |
245 | - # First dissolution gets the desugared input. | |
246 | - index = dissolve(expr) | |
245 | + # It's unclear whether we should jellify here. | |
246 | + # For learning purposes, it's important to be able to write directly to the heap... | |
247 | + # But also, we should prize normal forms and encourage users to see them as equivalent. | |
248 | + # For now, we'll dissolve, jellify, dissolve. | |
249 | + sexp = jellify(sexpify(resolve(dissolve(expr)))) | |
250 | + index = dissolve(parse(sexp)[0]) | |
247 | 251 | return jsonify({"index": index, "trail": trail}) |
248 | 252 | |
249 | 253 | if __name__ == "__main__": |
@@ -4,6 +4,7 @@ | ||
4 | 4 | import readline |
5 | 5 | import sys |
6 | 6 | from textwrap import dedent |
7 | +import urllib.parse | |
7 | 8 | |
8 | 9 | import requests |
9 | 10 |
@@ -39,7 +40,11 @@ def sexpify(expr): | ||
39 | 40 | else: return expr |
40 | 41 | |
41 | 42 | def fetchDipper(base, name): |
42 | - return getJSON(base + "/dip/" + name) | |
43 | + component = urllib.parse.quote(name, safe="") | |
44 | + return getJSON(base + "/dip/" + component) | |
45 | + | |
46 | +def dissolve(base, sexp): | |
47 | + return requests.post(base + "/dissolve", data=sexp).json() | |
43 | 48 | |
44 | 49 | class DipperCompleter: |
45 | 50 | def __init__(self, dippers): |
@@ -63,18 +68,13 @@ def repl(base): | ||
63 | 68 | done = True |
64 | 69 | else: |
65 | 70 | if line.startswith(":"): |
66 | - print("I think it's a command") | |
71 | + print("I don't have any commands, sorry") | |
67 | 72 | else: |
68 | - print("I think it's a sugared Cammy expression") | |
69 | - if line.startswith("("): | |
70 | - print("I think it's an application") | |
71 | - else: | |
72 | - print("I'm gonna guess that it's a dip!") | |
73 | - obj = fetchDipper(base, line) | |
74 | - trail = obj.get("trail", "").strip() | |
75 | - if trail: print("Trail:", trail) | |
76 | - term = extractor.fullyExtract(obj["expr"]) | |
77 | - print("Term:", sexpify(term)) | |
73 | + obj = dissolve(base, line) | |
74 | + trail = obj.get("trail", "").strip() | |
75 | + if trail: print("Trail:", trail) | |
76 | + term = extractor.fullyExtract(obj["index"]) | |
77 | + print("Term:", sexpify(term)) | |
78 | 78 | |
79 | 79 | def installCompletion(dippers): |
80 | 80 | readline.parse_and_bind("tab: complete") |
@@ -82,7 +82,7 @@ def installCompletion(dippers): | ||
82 | 82 | readline.set_completer_delims("() ") |
83 | 83 | |
84 | 84 | if __name__ == "__main__": |
85 | - base = sys.argv[-1] | |
85 | + base = sys.argv[1] | |
86 | 86 | dippers = fetchDippers(base) |
87 | 87 | installCompletion(dippers) |
88 | 88 | repl(base) |
@@ -40,10 +40,6 @@ | ||
40 | 40 | * Perhaps generate monad instances automatically? |
41 | 41 | * Basic enums, for better sum types |
42 | 42 | * Haskell-style ADTs are basically polynomial functors |
43 | -* REPL improvements | |
44 | - * : commands | |
45 | - * help, describe commands | |
46 | - * edit an atom's trail | |
47 | 43 | * The case for trees |
48 | 44 | * data Tree a = Leaf | Branch a (Tree a) (Tree a) |
49 | 45 | * well-founded whenever lists are well-founded |
@@ -96,8 +92,6 @@ | ||
96 | 92 | * Special case of reader monad |
97 | 93 | * Distributive law: [N, X] + 1 → [N, X + 1] |
98 | 94 | * Creates a stream+maybe monad: X → [N, X + 1] |
99 | -* Subtypes? | |
100 | - * Interval type? | |
101 | 95 | * Moore machines: For state type Q and input type S, Q × S -> Q |
102 | 96 | * Suppose we have output/observation type O and Q -> O |
103 | 97 | * Then Moore machines are equivalent to compact encodings [S] -> O |
@@ -130,8 +124,6 @@ | ||
130 | 124 | * https://okmij.org/ftp/continuations/undelimited.html |
131 | 125 | * It's about time to rewrite the multisampling logic in Cammy |
132 | 126 | * Mostly just needs pixel radius to be passed to image |
133 | -* Use Elliott's techniques to compile to a graph? | |
134 | - * And then display the graph! | |
135 | 127 | * Zippers http://strictlypositive.org/diff.pdf |
136 | 128 | * Zipper for lists looks like existing FIFO code, just needs the helpers |
137 | 129 | * Lenses? |
@@ -375,6 +367,11 @@ | ||
375 | 367 | * Let's rewrite Honey with FastAPI! |
376 | 368 | * And use PyPy! |
377 | 369 | * But not right now! |
370 | +* New REPL | |
371 | + * Not sure if there's much need for commands | |
372 | + * Making new dippers, maybe? | |
373 | + * Realized that ":" is not the best command-starter | |
374 | + * Technically ")" would be the best choice since it can't start a legal term | |
378 | 375 | * Slogans? |
379 | 376 | * Cammy is compositional |
380 | 377 | * Cammy is chimeric |