|
|
|
@ -5,8 +5,6 @@ |
|
|
|
|
#include <vector> |
|
|
|
|
#include "error.hpp" |
|
|
|
|
|
|
|
|
|
bool type::is_arrow(const type_mgr& mgr) const { return false; } |
|
|
|
|
|
|
|
|
|
void type_scheme::print(const type_mgr& mgr, std::ostream& to) const { |
|
|
|
|
if(forall.size() != 0) { |
|
|
|
|
to << "forall "; |
|
|
|
@ -36,21 +34,17 @@ void type_var::print(const type_mgr& mgr, std::ostream& to) const { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool type_var::is_arrow(const type_mgr& mgr) const { |
|
|
|
|
auto it = mgr.types.find(name); |
|
|
|
|
if(it != mgr.types.end()) { |
|
|
|
|
return it->second->is_arrow(mgr); |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void type_base::print(const type_mgr& mgr, std::ostream& to) const { |
|
|
|
|
to << name; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void type_internal::print(const type_mgr& mgr, std::ostream& to) const { |
|
|
|
|
to << "!" << name; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void type_arr::print(const type_mgr& mgr, std::ostream& to) const { |
|
|
|
|
bool print_parenths = left->is_arrow(mgr); |
|
|
|
|
type_var* var; |
|
|
|
|
bool print_parenths = dynamic_cast<type_arr*>(mgr.resolve(left, var).get()) != nullptr; |
|
|
|
|
if(print_parenths) to << "("; |
|
|
|
|
left->print(mgr, to); |
|
|
|
|
if(print_parenths) to << ")"; |
|
|
|
@ -58,10 +52,6 @@ void type_arr::print(const type_mgr& mgr, std::ostream& to) const { |
|
|
|
|
right->print(mgr, to); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool type_arr::is_arrow(const type_mgr& mgr) const { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void type_app::print(const type_mgr& mgr, std::ostream& to) const { |
|
|
|
|
constructor->print(mgr, to); |
|
|
|
|
to << "*"; |
|
|
|
@ -131,7 +121,10 @@ void type_mgr::unify(type_ptr l, type_ptr r, const std::optional<yy::location>& |
|
|
|
|
return; |
|
|
|
|
} else if((lid = dynamic_cast<type_base*>(l.get())) && |
|
|
|
|
(rid = dynamic_cast<type_base*>(r.get()))) { |
|
|
|
|
if(lid->name == rid->name && lid->arity == rid->arity) return; |
|
|
|
|
if(lid->name == rid->name && |
|
|
|
|
lid->arity == rid->arity && |
|
|
|
|
lid->is_internal() == rid->is_internal()) |
|
|
|
|
return; |
|
|
|
|
} else if((lapp = dynamic_cast<type_app*>(l.get())) && |
|
|
|
|
(rapp = dynamic_cast<type_app*>(r.get()))) { |
|
|
|
|
unify(lapp->constructor, rapp->constructor, loc); |
|
|
|
|