diff options
-rw-r--r-- | src/pprint.cpp | 1 | ||||
-rw-r--r-- | src/resp.hpp | 5 | ||||
-rw-r--r-- | src/unify.cpp | 14 |
3 files changed, 13 insertions, 7 deletions
diff --git a/src/pprint.cpp b/src/pprint.cpp index 506d24e..d7ca0f8 100644 --- a/src/pprint.cpp +++ b/src/pprint.cpp @@ -102,7 +102,6 @@ print_to(ostream& out, const AST* ast, unsigned indent, CEnv* cenv, bool types) switch (type->kind) { case AType::VAR: return out << "?" << type->id; case AType::NAME: return out << type->head(); - case AType::DOTS: return out << "..."; case AType::EXPR: break; // will catch Tuple case below } } diff --git a/src/resp.hpp b/src/resp.hpp index 8fa4b9b..bc8c9ae 100644 --- a/src/resp.hpp +++ b/src/resp.hpp @@ -353,7 +353,7 @@ list_contains(const ATuple* head, const AST* child) { /// Type Expression, e.g. "Int", "(Fn (Int Int) Float)" struct AType : public ATuple { - enum Kind { VAR, NAME, EXPR, DOTS }; + enum Kind { VAR, NAME, EXPR }; AType(const ASymbol* s, Kind k) : ATuple(s, NULL, s->loc), kind(k), id(0) { tag(T_TYPE); } AType(Cursor c, unsigned i) : ATuple(c), kind(VAR), id(i) { tag(T_TYPE); } AType(Cursor c, Kind k=EXPR) : ATuple(c), kind(k), id(0) { tag(T_TYPE); } @@ -454,7 +454,6 @@ AST::operator==(const AST& rhs) const case AType::VAR: return me->id == rt->id; case AType::NAME: return me->head()->str() == rt->head()->str(); case AType::EXPR: return list_equals(me, rt); - case AType::DOTS: return true; } } return false; // never reached @@ -638,7 +637,7 @@ struct TEnv : public Env<const AType*> { : penv(p) , varID(1) , Closure(new AType(penv.sym("Closure"), AType::NAME)) - , Dots(new AType(Cursor(), AType::DOTS)) + , Dots(new AType(penv.sym("..."), AType::NAME)) , Fn(new AType(penv.sym("Fn"), AType::NAME)) , Tup(new AType(penv.sym("Tup"), AType::NAME)) , U(new AType(penv.sym("U"), AType::NAME)) diff --git a/src/unify.cpp b/src/unify.cpp index 48818e9..52a3265 100644 --- a/src/unify.cpp +++ b/src/unify.cpp @@ -119,6 +119,13 @@ Constraints::replace(const AType* s, const AType* t) return *this; } +static inline bool +is_dots(const AST* ast) +{ + const AType* type = ast->as_type(); + return (type->kind == AType::NAME && type->head()->str() == "..."); +} + /// Unify a type constraint set (TAPL 22.4) Subst unify(const Constraints& constraints) @@ -143,13 +150,14 @@ unify(const Constraints& constraints) for (; si != s->end() && ti != t->end(); ++si, ++ti) { const AType* st = (*si)->as_type(); const AType* tt = (*ti)->as_type(); - if (st->kind == AType::DOTS || tt->kind == AType::DOTS) + if (is_dots(st) || is_dots(tt)) return unify(cp); else cp.push_back(Constraint(st, tt)); } - if ( (si == s->end() && (ti == t->end() || (*ti)->as_type()->kind == AType::DOTS)) - || (ti == t->end() && (*si)->as_type()->kind == AType::DOTS)) + if ((si == s->end() && ti == t->end()) + || (si != s->end() && is_dots(*si)) + || (ti != t->end() && is_dots(*ti))) return unify(cp); } throw Error(s->loc, |