def replace_unfinished_leafs_raw(self, new_subtrees): assert len(new_subtrees) > 0 subtree = new_subtrees.pop(0) mu = sub.mgu(self.typ, subtree.typ) assert not mu.is_failed() new_subtree = subtree.apply_sub(mu) return new_subtree, mu
def gen_one_leaf_uf(self, uf_tree, typ, n): ctx_declaration = self.gamma.ctx.get(uf_tree.sym, None) assert ctx_declaration is not None f = fresh(ctx_declaration.typ, typ, n) mu = sub.mgu(typ, f.typ) assert not mu.is_failed() return Leaf(uf_tree.sym, mu(typ)), f.n
def ts1_static(gamma: Context, typ: Typ, n): ret = [] for ctx_declaration in gamma.ctx.values(): f = fresh(ctx_declaration.typ, typ, n) mu = mgu(typ, f.typ) if not mu.is_failed(): sigma = mu.restrict(typ) ret.append(PreTs1Res(ctx_declaration.sym, sigma)) return ret
def subs_uf_sym(gamma, n, typ, uf_tree): # TODO factor out uf_tree.sym to args ctx_declaration = gamma.ctx.get(uf_tree.sym, None) if ctx_declaration is None: return [] f = fresh(ctx_declaration.typ, typ, n) mu = sub.mgu(typ, f.typ) if mu.is_failed(): return [] sigma = mu.restrict(typ) return [sub.SubRes(1, sigma, f.n)]
def successors_typed(self, gamma, n): alpha, n1 = new_var(self.typ, n) typ_f = TypTerm.make_arrow(alpha, self.typ) ret = [(App(UnfinishedLeaf(typ_f), UnfinishedLeaf(alpha), self.typ), sub.Sub(), n1)] for ctx_declaration in gamma.ctx.values(): fresh_res = fresh(ctx_declaration.typ, self.typ, n) mu = sub.mgu(self.typ, fresh_res.typ) if not mu.is_failed(): sigma = mu.restrict(self.typ) leaf = Leaf(ctx_declaration.sym, sigma(self.typ)) ret.append((leaf, sigma, fresh_res.n)) return ret
def is_well_typed_acc(self, gamma, local_vars, n): if self.sym == INTERNAL_PAIR_CONSTRUCTOR_SYM: t_s = T_INTERNAL_PAIR_CONSTRUCTOR else: if self.sym not in gamma.ctx: return False, None t_s = gamma.ctx[self.sym].typ fr = fresh(t_s, self.typ, n) mu = sub.mgu(self.typ, fr.typ) return not mu.is_failed(), fr.n