A categorical programming language
修订版 | c49055b3f863b8ab587f40df0c787bd048d9a85c (tree) |
---|---|
时间 | 2022-02-28 08:56:34 |
作者 | Corbin <cds@corb...> |
Commiter | Corbin |
Catch infinite types during extraction.
@@ -107,6 +107,9 @@ class TypeExtractor(object): | ||
107 | 107 | self.d[index] = LETTERS[len(self.d)] |
108 | 108 | |
109 | 109 | def extractType(self, cs, var): |
110 | + return self.go(cs, var, []) | |
111 | + | |
112 | + def go(self, cs, var, seen): | |
110 | 113 | sexp = cs.walk(var) |
111 | 114 | if isinstance(sexp, Hole): |
112 | 115 | if sexp.index not in self.d: |
@@ -115,7 +118,10 @@ class TypeExtractor(object): | ||
115 | 118 | elif isinstance(sexp, Atom): |
116 | 119 | return sexp.symbol |
117 | 120 | elif isinstance(sexp, Functor): |
118 | - args = [self.extractType(cs, unhole(arg)) for arg in sexp.arguments] | |
121 | + if var in seen: | |
122 | + # XXX split exceptions? | |
123 | + raise UnificationFailed("tried to extract infinite type") | |
124 | + args = [self.go(cs, unhole(arg), seen + [var]) for arg in sexp.arguments] | |
119 | 125 | if sexp.constructor == "hom": |
120 | 126 | return "[%s, %s]" % (args[0], args[1]) |
121 | 127 | elif sexp.constructor == "pair": |
@@ -1,5 +1,6 @@ | ||
1 | 1 | import os |
2 | 2 | import os.path |
3 | +import sys | |
3 | 4 | |
4 | 5 | from cammylib.arrows import buildArrow, BuildProblem |
5 | 6 | from cammylib.hive import Hive, MissingAtom |
@@ -61,3 +62,6 @@ def main(argv): | ||
61 | 62 | def target(driver, *args): |
62 | 63 | driver.exe_name = "cammy-weave" |
63 | 64 | return main, None |
65 | + | |
66 | +if __name__ == "__main__": | |
67 | + main(sys.argv) |