#include "pattern.hpp" #include "error.hpp" #include "type_checker.hpp" #include "type_manager.hpp" namespace lily { type* pattern_var::check_modifying(type_manager& mgr, std::shared_ptr env) { type* parameter = mgr.create_type(); env->set_type(name, parameter); return parameter; } type* pattern_cons::check_modifying(type_manager& mgr, std::shared_ptr env) { type* constructor_type = env->get_identifier_type(name); int arity = constructor_type->arity(); if(arity != vnames.size()) throw error("invalid number of arguments to constructor"); if(arity == 0) { return constructor_type; } else { type_func* func_type; type* current = constructor_type; int index = 0; while((func_type = dynamic_cast(current))) { env->set_type(vnames[index++], func_type->left); current = func_type->right; } return current; } } }