Type Inference for Overloading without Restrictions, Declarations or Annotations Carlos Camar˜ ao 1 and Luc´ ılia Figueiredo 2 1 Universidade Federal de Minas Gerais, DCC-ICEX Belo Horizonte 31270-010, Brasil camarao@dcc.ufmg.br 2 Universidade Federal de Ouro Preto, DECOM-ICEB Ouro Preto 35400-000, Brasil lucilia@dcc.ufmg.br Abstract. This article presents a type system based on the Damas- Milner system [DM82], that supports overloading. Types of overloaded symbols are constrained polymorphic types. The work is related to Haskell type classes [Wad89,NP93,HHJW96], System O [OWW95] and other type systems with similar forms of constrained types [Kae88,Smi91,Jon94,DCO96]. Restrictions imposed in these systems with respect to overloading are eliminated. User-defined global and local overloading is supported with- out restrictions. There is no need for declarations or annotations of any sort. No language construct is added in order to cope with overloading. The type system uses a context-dependent overloading policy, which is specified by means of a predicate used in a single inference rule. Over- loading of functions defined over different type constructors is supported, as done with Haskell’s constructor classes. No monomorphism restriction is required in order to solve ambiguity problems. The system uses an open-world approach, in which new overloaded def- initions can be introduced with types automatically reflecting the new definitions. The article also presents a type inference algorithm for the system, which is proved to be sound and to compute principal typings. 1 Introduction The problems with the treatment of overloading in languages such as SML [MTH89,Pau96] and Miranda [Tur85], that provide (parametric) polymorphism and type inference, have been discussed for example by Wadler and Blott [Wad89]. For instance, square x = x * x cannot be written in SML, the reason being that * is overloaded for integers and reals. Equality is treated in a special way in SML. For example, the type of a function member, that tests membership in a list, namely ‘‘a list -> ‘‘a -> bool, involves a special polymorphic type variable ‘‘a, constrained so that its instances must admit equality. In Miranda, this type is not constrained in this