src/main.cpp
/* typecheck an instance for whether it properly overloads the type class with
 * which it is associated */
typecheck an instance for whether it properly overloads the type class with
which it is associated
typecheck an instance for whether it properly overloads the type class with which it is associated
void check_instance_for_type_class_overloads(
    const Instance *instance,
    const TypeClass *type_class,
    const DataCtorsMap &data_ctors_map,
    std::vector<const Decl *> &instance_decls,
    types::SchemeResolver &scheme_resolver,
    CheckedDefinitionsByName &checked_defns) {
  if (instance->class_predicate->params.size() !=
      type_class->type_var_ids.size()) {
    throw user_error(instance->get_location(),
                     "the number of params on %s does not equal "
                     "the number of type variables on %s",
                     instance->str().c_str(), type_class->str().c_str());
  }
  types::Map subst;
  int i = 0;
  for (auto &type_var_id : type_class->type_var_ids) {
    subst[type_var_id.name] = instance->class_predicate->params[i++];
  }
  std::set<std::string> names_checked;
  for (auto pair : type_class->overloads) {
    auto name = pair.first;
    auto type = pair.second;
    check_instance_for_type_class_overload(
        name, type, type_class, instance, subst, data_ctors_map, names_checked,
        scheme_resolver,
        type_class->class_predicates , checked_defns);
  }
  for (const Decl *decl : instance->decls) {
    if (!in(decl->id.name, names_checked)) {
      throw user_error(decl->id.location,
                       "extraneous declaration %s found in instance %s "
                       "(names_checked = {%s})",
                       decl->id.str().c_str(),
                       instance->class_predicate->str().c_str(),
                       join(names_checked, ", ").c_str());
    }
  }
}
void check_instance_for_type_class_overloads ( const Instance * instance , const TypeClass * type_class , const DataCtorsMap & data_ctors_map , std :: vector < const Decl * > & instance_decls , types :: SchemeResolver & scheme_resolver , CheckedDefinitionsByName & checked_defns ) { if ( instance -> class_predicate -> params . size ( ) != type_class -> type_var_ids . size ( ) ) { throw user_error ( instance -> get_location ( ) , " " " " , instance -> str ( ) . c_str ( ) , type_class -> str ( ) . c_str ( ) ) ; } types :: Map subst ; int i = 0 ; for ( auto & type_var_id : type_class -> type_var_ids ) { subst [ type_var_id . name ] = instance -> class_predicate -> params [ i ++ ] ; } std :: set < std :: string > names_checked ; for ( auto pair : type_class -> overloads ) { auto name = pair . first ; auto type = pair . second ; check_instance_for_type_class_overload ( name , type , type_class , instance , subst , data_ctors_map , names_checked , scheme_resolver , type_class -> class_predicates , checked_defns ) ; } for ( const Decl * decl : instance -> decls ) { if ( ! in ( decl -> id . name , names_checked ) ) { throw user_error ( decl -> id . location , " " " " , decl -> id . str ( ) . c_str ( ) , instance -> class_predicate -> str ( ) . c_str ( ) , join ( names_checked , " " ) . c_str ( ) ) ; } } }
typecheck an instance for whether it properly overloads the type class with
 which it is associated
typecheck an instance for whether it properly overloads the type class with which it is associated
/* make a template for the types that the instance implementation should
   * conform to */ /* check whether this instance properly implements the given type class */ /*, type_class->defaults*/ /* check for unrelated declarations inside of an instance */