A categorical programming language
修订版 | aefa9fce4e94ae7dc359bc4cb0ff1a6fcc4aadb1 (tree) |
---|---|
时间 | 2022-10-13 12:16:41 |
作者 | Corbin <cds@corb...> |
Commiter | Corbin |
Expand dissolved expressions correctly.
This might be a hack.
@@ -113,11 +113,15 @@ def sexpify(expr): | ||
113 | 113 | @app.route("/extract/<int:token>/type") |
114 | 114 | def getType(token): |
115 | 115 | expr = resolve(token) |
116 | - types = subprocess.check_output(MOVELIST + "cammy-type", | |
117 | - input=sexpify(expr).encode("utf-8")).decode("utf-8").split("\n") | |
118 | - s, _ = parse(types[0].strip()) | |
119 | - t, _ = parse(types[1].strip()) | |
120 | - return jsonify({"source": s, "target": t}) | |
116 | + try: | |
117 | + types = subprocess.check_output(MOVELIST + "cammy-type", | |
118 | + input=sexpify(expr).encode("utf-8")).decode("utf-8").split("\n") | |
119 | + s, _ = parse(types[0].strip()) | |
120 | + t, _ = parse(types[1].strip()) | |
121 | + return jsonify({"source": s, "target": t}) | |
122 | + except subprocess.CalledProcessError: | |
123 | + print("Couldn't typecheck", sexpify(expr)) | |
124 | + raise | |
121 | 125 | |
122 | 126 | @app.route("/dippers") |
123 | 127 | def dippers(): |
@@ -133,12 +137,16 @@ def resolve(i): | ||
133 | 137 | def dissolve(sexp): |
134 | 138 | if isinstance(sexp, int): return sexp |
135 | 139 | if isinstance(sexp, str): |
140 | + if sexp in symbols: | |
141 | + return symbols[sexp][0] | |
136 | 142 | if sexp not in strs: |
137 | 143 | strs[sexp] = len(heap) |
138 | 144 | heap.append(sexp) |
139 | 145 | return strs[sexp] |
140 | 146 | else: |
141 | 147 | merged = tuple([sexp[0]] + [dissolve(arg) for arg in sexp[1:]]) |
148 | + if merged[0] in templates: | |
149 | + merged = substitute(merged[1:], templates(merged[0])) | |
142 | 150 | if merged not in tuples: |
143 | 151 | tuples[merged] = len(heap) |
144 | 152 | heap.append(merged) |