diff options
Diffstat (limited to 'src/unify.cpp')
-rw-r--r-- | src/unify.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/unify.cpp b/src/unify.cpp index 3f06868..93dd78b 100644 --- a/src/unify.cpp +++ b/src/unify.cpp @@ -92,7 +92,7 @@ Subst::compose(const Subst& delta, const Subst& gamma) } /// Replace all occurrences of @a s with @a t -void +Constraints& Constraints::replace(AType* s, AType* t) { for (Constraints::iterator c = begin(); c != end();) { @@ -103,6 +103,7 @@ Constraints::replace(AType* s, AType* t) substitute(c->second, s, t); c = next; } + return *this; } /// Unify a type constraint set (TAPL 22.4) @@ -112,19 +113,17 @@ unify(const Constraints& constraints) if (constraints.empty()) return Subst(); - AType* s = constraints.begin()->first; - AType* t = constraints.begin()->second; - Constraints cp = constraints; - cp.erase(cp.begin()); + Constraints::const_iterator i = constraints.begin(); + AType* s = i->first; + AType* t = i->second; + Constraints cp(++i, constraints.end()); if (*s == *t) { return unify(cp); } else if (s->kind == AType::VAR && !t->contains(s)) { - cp.replace(s, t); - return Subst::compose(unify(cp), Subst(s, t)); + return Subst::compose(unify(cp.replace(s, t)), Subst(s, t)); } else if (t->kind == AType::VAR && !s->contains(t)) { - cp.replace(t, s); - return Subst::compose(unify(cp), Subst(t, s)); + return Subst::compose(unify(cp.replace(t, s)), Subst(t, s)); } else if (s->kind == AType::EXPR && t->kind == AType::EXPR) { AType::iterator si = s->begin() + 1; AType::iterator ti = t->begin() + 1; |