Bounded quantification explained

In type theory, bounded quantification (also bounded polymorphism or constrained genericity) refers to universal 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 setting of System F<:, but is available in modern object-oriented languages supporting parametric polymorphism (generics) such as Java, C# and Scala.

Overview

The purpose of bounded quantification is to allow for polymorphic functions to depend on some specific behaviour of objects instead of type inheritance. 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 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.[1]

Example

This kind of type constraint can be expressed in Java 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 functions. The Test.min function uses simple bounded quantification and does not ensure the objects are mutually comparable, 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 → T

where

Comparable[T] =

interface Comparable

public class Integer implements Comparable

public class String implements Comparable

public class Test

See also

References

. Benjamin C. Pierce. Types and Programming Languages. MIT Press. 2002. 978-0-262-16209-8., Chapter 26: Bounded quantification

External links

Notes and References

  1. F-bounded polymorphism for object-oriented programming. Canning, Cook, Hill, Olthof and Mitchell. http://dl.acm.org/citation.cfm?id=99392