In
type theory
In mathematics, logic, and computer science, a type theory is the formal presentation of a specific type system, and in general type theory is the academic study of type systems. Some type theories serve as alternatives to set theory as a foundat ...
, bounded quantification (also bounded polymorphism or constrained genericity) refers to
universal
Universal is the adjective for universe.
Universal may also refer to:
Companies
* NBCUniversal, a media and entertainment company
** Universal Animation Studios, an American Animation studio, and a subsidiary of NBCUniversal
** Universal TV, a t ...
or
existential quantifiers which are restricted ("bounded") to range only over the subtypes of a particular type. Bounded quantification is an interaction of
parametric polymorphism with
subtyping. Bounded quantification has traditionally been studied in the
functional
Functional may refer to:
* Movements in architecture:
** Functionalism (architecture)
** Form follows function
* Functional group, combination of atoms within molecules
* Medical conditions without currently visible organic basis:
** Functional sy ...
setting of
System F<:, but is available in modern
object-oriented language
Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pro ...
s supporting
parametric polymorphism (
generics
Generic or generics may refer to:
In business
* Generic term, a common name used for a range or class of similar things not protected by trademark
* Generic brand, a brand for a product that does not have an associated brand or trademark, other ...
) such as
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
,
C# and
Scala.
Overview
The purpose of bounded quantification is to allow for
polymorphic function
In programming language theory and type theory, polymorphism is the provision of a single interface (computing), interface to entities of different Data type, types or the use of a single symbol to represent multiple different types.: "Polymorph ...
s to depend on some specific behaviour of objects instead of
type inheritance
In object-oriented programming, inheritance is the mechanism of basing an object or class upon another object ( prototype-based inheritance) or class ( class-based inheritance), retaining similar implementation. Also defined as deriving new classe ...
. It assumes a record-based model for object classes, where every class member is a record element and all class members are named functions. Object attributes are represented as functions that take no argument and return an object. The specific behaviour is then some function name along with the types of the arguments and the return type. Bounded quantification allows to considers all objects with such a function. An example would be a polymorphic
min
function that considers all objects that are comparable to each other.
F-bounded quantification
''F''-bounded quantification or recursively bounded quantification, introduced in 1989, allows for more precise typing of functions that are applied on recursive types. A recursive type is one that includes a function that uses it as a type for some argument or its return value.
[''F''-bounded polymorphism for object-oriented programming. Canning, ]Cook
Cook or The Cook may refer to:
Food preparation
* Cooking, the preparation of food
* Cook (domestic worker), a household staff member who prepares food
* Cook (professional), an individual who prepares food for consumption in the food industry
* ...
, Hill, Olthof and Mitchell
Mitchell may refer to:
People
*Mitchell (surname)
*Mitchell (given name)
Places Australia
* Mitchell, Australian Capital Territory, a light-industrial estate
* Mitchell, New South Wales, a suburb of Bathurst
* Mitchell, Northern Territo ...
. http://dl.acm.org/citation.cfm?id=99392
Example
This kind of type constraint can be expressed in
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
with a generic interface. The following example demonstrates how to describe types that can be compared to each other and use this as typing information in
polymorphic function
In programming language theory and type theory, polymorphism is the provision of a single interface (computing), interface to entities of different Data type, types or the use of a single symbol to represent multiple different types.: "Polymorph ...
s. The
Test.min
function uses simple bounded quantification and does not preserve the type of the assigned types, in contrast with the
Test.Fmin
function which uses F-bounded quantification.
In mathematical notation, the types of the two functions are
:min: ∀ T, ∀ S ⊆ . S → S → S
:Fmin: ∀ T ⊆ Comparable
T → T → T
where
:Comparable
=
interface Comparable
class Integer implements Comparable
class String implements Comparable
class Test
See also
*
Covariance and contravariance (computer science)
Many programming language type systems support subtyping. For instance, if the type is a subtype of , then an expression of type should be substitutable wherever an expression of type is used.
Variance refers to how subtyping between more comp ...
*
Curiously recurring template pattern
The curiously recurring template pattern (CRTP) is an idiom, originally in C++, in which a class X derives from a class template instantiation using X itself as a template argument. More generally it is known as F-bound polymorphism, and it is a f ...
*
Wildcard (Java)
In the Java programming language, the wildcard ? is a special kind of type argument that controls the type safety of the use of generic (parameterized) types. It can be used in variable declarations and instantiations as well as in method definitio ...
Notes
References
*
*
Peter S. Canning
Peter may refer to:
People
* List of people named Peter, a list of people and fictional characters with the given name
* Peter (given name)
** Saint Peter (died 60s), apostle of Jesus, leader of the early Christian Church
* Peter (surname), a sur ...
,
William R. Cook,
Walter L. Hill,
John C. Mitchell
John Clifford Mitchell is professor of computer science and (by courtesy) electrical engineering at Stanford University. He has published in the area of programming language theory and computer security.John C. Mitchellwas the Vice Provost for T ...
, and
William Olthoff
William is a male given name of Germanic origin.Hanks, Hardcastle and Hodges, ''Oxford Dictionary of First Names'', Oxford University Press, 2nd edition, , p. 276. It became very popular in the English language after the Norman conquest of Eng ...
"F-bounded polymorphism for object-oriented programming" In ''Conference on Functional Programming Languages and Computer Architecture'', 1989.
*
Benjamin C. Pierce
Benjamin Crawford Pierce is the Henry Salvatori Professor of computer science at the University of Pennsylvania. Pierce joined Penn in 1998 from Indiana University and held research positions at the University of Cambridge and the University of E ...
"Intersection types and bounded polymorphism". ''Lecture Notes in Computer Science'' 664, 1993.
*
Gilad Bracha
Gilad Bracha is a software engineer at F5 Networks, and formerly at Google, where he was on the Dart programming language team. He is creator of the Newspeak language, and co-author of the second and third editions of the Java Language Specificati ...
,
Martin Odersky,
David Stoutamire
David (; , "beloved one") (traditional spelling), , ''Dāwūd''; grc-koi, Δαυΐδ, Dauíd; la, Davidus, David; gez , ዳዊት, ''Dawit''; xcl, Դաւիթ, ''Dawitʿ''; cu, Давíдъ, ''Davidŭ''; possibly meaning "beloved one". w ...
, and
Philip Wadler
Philip Lee Wadler (born April 8, 1956) is an American computer scientist known for his contributions to programming language design and type theory. He is the chair of Theoretical Computer Science at the Laboratory for Foundations of Computer S ...
. "Making the future safe for the past: Adding genericity to the Java programming language". In ''Object-Oriented Programming: Systems, Languages, Applications'' (OOPSLA). ACM, October 1998.
*
Andrew Kennedy and
Don Syme
Don Syme is an Australian computer scientist and a Principal Researcher at Microsoft Research, Cambridge, U.K. He is the designer and architect of the F# programming language, described by a reporter as being regarded as "the most original new f ...
. "Design and Implementation of Generics for the .NET Common Language Runtime". In ''Programming Language Design and Implementation'', 2001.
* {{cite book, last=Pierce, first=Benjamin C., authorlink=Benjamin C. Pierce, title=Types and Programming Languages, publisher=MIT Press, date=2002, isbn=978-0-262-16209-8, Chapter 26: Bounded quantification
External links
Bounded Polymorphismat the
Portland Pattern Repository
"F-bounded Polymorphism"in ''The Cecil Language: Specification and Rationale''
Polymorphism (computer science)
Object-oriented programming
Type theory
Articles with example Java code