An Approach to Overloading with Polymorphism (original) (raw)
Related papers
A Type System for Context-dependent Overloading
Electronic Notes in Theoretical Computer Science, 1998
This article presents a type system for context-dependent overloading, based on the notion of constrained types. These are types constrained by the definition of functions or constants of given types. This notion supports both overloading and a form of subtyping, and is related to Haskell type classes[11,2], System O [7] and other systems with constrained types[9,8]. We study an extension
Types, Data Abstraction, and Polymorphism
Our objective is to understand the notion of type in programming languages, present a model of typed, polymorphic programming languages that reflects recent research in type theory, and examine the relevance of recent research to the design of practical programming languages. Object-oriented languages provide both a framework and a motivation for exploring the interaction among the concepts of type, data abstraction, and polymorphism, since they extend the notion of type to data abstraction and since type inheritance is an important form of polymorphism. We develop a X-calculus-based model for type systems that allows us to explore these interactions in a simple setting, unencumbered by complexities of production programming languages. The evolution of languages from untyped universes to monomorphic and then polymorphic type systems is reviewed. Mechanisms for polymorphism such as overloading, coercion, subtyping, and parameterization are examined. A unifying framework for polymorphic type systems is developed in terms of the typed A-calculus augmented to include binding of types by quantification as well as binding of values by abstraction. The typed X-calculus is augmented by universal quantification to model generic functions with type parameters, existential quantification and packaging (information hiding) to model abstract data types, and bounded quantification to model subtypes and type inheritance. In this way we obtain a simple and precise characterization of a powerful type system that includes abstract data types, parametric polymorphism, and multiple inheritance in a single consistent framework. The mechanisms for type checking for the augmented X-calculus are discussed. The augmented typed X-calculus is used as a programming language for a variety of illustrative examples. We christen this language Fun because fun instead of X is the functional abstraction keyword and because it is pleasant to deal with. Fun is mathematically simple and can serve as a basis for the design and implementation of real programming languages with type facilities that are more powerful and expressive than those of existing programming languages. In particular, it provides a basis for the design of strongly typed object-oriented languages.
Function Overloading Implementation in C++ A Static Type of Polymorphism
In this article the function overloading in object oriented programming is elaborated and how they are implemented in C++. The language supports a variety of programming styles. Here we are describing the polymorphism and its types in brief. The main stress is given on the function overloading implementation styles in the language. The polymorphic nature of languages has advantages like that we can add new code without requiring changes to the other classes and interfaces (in Java language) are easily implemented. In this technique, the run-time overhead is also introduced in dynamic binding which increases the execution time of the software. But there are no such types of overheads in this static type of polymorphism because everything is resolved at the time of compile time.
Type Inference for Overloading without Restrictions, Declarations or Annotations
Lecture Notes in Computer Science, 1999
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 without 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. Overloading 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 definitions 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.
First Class Overloading via Insersection Type Parameters⋆
The Hindley-Milner type system imposes the restriction that function parameters must have monomorphic types. Lifting this restric-tion and providing system F "first class" polymorphism is clearly desir-able, but comes with the difficulty that inference of types for system F is undecidable. More practical type systems incorporating types of higher-rank have recently been proposed, that rely on system F but require type annotations for the definition of functions with polymorphic type parameters. However, these type annotations inevitably disallow some possible uses of higher-rank functions. To avoid this problem and to pro-mote code reuse, we explore using intersection types for specifying the types of function parameters that are used polymorphically inside the function body, allowing a flexible use of such functions, on applications to both polymorphic or overloaded arguments.
ACM SIGPLAN Notices, 2002
We present a minimal extension of the Hindley/Milner system to allow for overloading of identifiers. Our approach relies on a combination of the HM(X) type system framework with Constraint Handling Rules (CHRs). CHRs are a declarative language for writing incremental constraint solvers. CHRs allow us to precisely describe the relationships among overloaded identifiers. Under some sufficient conditions on the CHRs
A Calculus for Overload Functions with Subtyping
We present a simple extension of typed -calculus where functions can be overloaded by putting di erent \branches of code" together. When the function is applied, the branch to execute is chosen according to a particular selection rule which depends on the type of the argument. The crucial feature of the present approach is that the branch selection depends on the \run-time type" of the argument, which may di er from its compile-time type, because of the existence of a subtyping relation among types. Hence overloading cannot be eliminated by a static analysis of code, but is an essential feature to be dealt with during computation. We obtain in this way a type-dependent calculus, which di ers from the various -calculi where types do not play any rôle during computation. We prove Con uence and a generalized Subject-Reduction theorem for this calculus. We prove Strong Normalization for a \strati ed" subcalculus. The de nition of this calculus is guided by the understanding of object-oriented features and the connections between our calculus and object-orientedness are extensively stressed. We show that this calculus provides a foundation for typed object-oriented languages which solves some of the problems of the standard record-based approach.
Open and Closed Worlds for Overloading: a Definition and Support for Coexistence
Journal of Universal Computer Science, 2007
The type system of Haskell and some related systems are based on an open world approach for overloading. In an open world, the principal type of each overloaded symbol must be explicitly annotated (in Haskell, annotations occur in type class declarations) and a definition of an overloaded symbol is required to exist only when overloading is resolved. In a closed world, on the other hand, each principal type is determined according to the types of definitions that exist in the relevant context and, furthermore, overloading resolution for an expression considers only the context of the definition of its constituent symbols. In this paper we formally characterize open and closed worlds, and discuss their relative advantages. We present a type system that supports both approaches together, and compare the defined system with Haskell type classes extended with multi-parameter type classes and functional dependencies. We show in particular that functional dependencies are not necessary in order to support multi-parameter type classes, and present an alternative route.
F-Bounded polymorphism for object-oriented programming
Wegner as a means of typing functions that operate uniformly over all subtypes of a given type. They defined a simple "object" model and used bounded quantification to type-check functions that make sense on all objects having a specified set of "attributes." A more realistic presentation of object-oriented languages would allow objects that are elements of recursively-defined types. In this context, bounded quantification no longer serves its intended purpose. It is easy to find functions that makes sense on all objects having a specified set of methods, but which cannot be typed in the Cardelli-Wegner system. To provide a basis for typed polymorphic functions in object-oriented languages, we introduce F-bounded quantification. Some applications of F-bounded quantification are presented and semantic issues are discussed. Although our original motivation was to type polymorphic functions over objects, F-bounded quantification is a general form of polymorphism that seems useful whenever recursive type definitions and subtyping are used.
General Homomorphic Overloading
Lecture Notes in Computer Science, 2005
A general homomorphic overloading in a first-order type system is discussed. Type inference is applied within predefined classes each containing an arbitrary first-order subtyping hierarchy. We propose a computationally efficient type inference algorithm by converting the attendant constraint-satisfaction problem into the algebraic path problem for a constraint graph weighted with elements of a specially constructed non-commutative star semiring. The elements of the semiring are monotonic functions from integers to integers (including ±∞) with pointwise maximum and function composition as semiring operations. The computational efficiency of our method is due to Klene's algebraic path method's cubic complexity. Our algorithm is applicable to type inference in the presence of unknown external types and supports distributed type inference.