Parametric Polymorphism

A powerful expressive form that allows generic code to be written that applies to a range of types. An example is collection classes like Vector which are independent of the types of their constituent members. Parametric polymorphism allows classes and methods to accept types as parameters, in addition to their conventional parameters, meaning that classes can be abstracted with respect to types.

(from BrokenLink

-- ChanningWalton

ParametricPolymorphism is usually contrasted with AdHocPolymorphism. Quoting ChristopherStrachey:

Also see OnUnderstandingTypes.

It should probably be pointed out that ParametricPolymorphism as such is completely unrelated to ObjectOrientedProgramming (unlike the suggestion created by the link above). ParametricPolymorphism is a typical feature of all statically-typed FunctionalProgrammingLanguages, such as HaskellLanguage or MlLanguage. C++'s templates provide similar functionality, but unfortunately lack nice syntax, separate compilation and full type-safety at definition time. -- StephanHouben

ParametricPolymorphism comes ForFree in any language with first class types, but for reasons I don't understand, almost no languages have such. -- ThomasColthurst

A lot of people in the LanguagePissingMatch have pointed out that Java doesn't have ParametricPolymorphism. They're actually working on this as we speak. Go to the java language specification at (it's in there somewhere) and there should be something about planned updates. It includes assertions and ParametricPolymorphism.

The JavaCommunityProcess list of all specification requests does not list ParametricPolymorphism. The closest it comes is support for generic types. Can you provide a direct URL? I suspect that ParametricPolymorphism won't make it into any JVM since it requires changes to the JLS, perhaps to bytecodes, and may not be backwards compatible.

Surely the "Generics" feature of Java 1.5 provides ParametricPolymorphism, while CeePlusPlus's "Templates" provides AdHocPolymorphism? Or have I misunderstood the definitions of ParametricPolymorphism provided on this page? -- ChrisHandley

All of which C++ can do. But templates themselves are a technique for ParametricPolymorphism. Read the paper OnUnderstandingTypes; it explains all of the above quite well.

See also: IncludeFileParametricPolymorphism, PredicateTypes, PredicateDispatching


EditText of this page (last edited January 2, 2013) or FindPage with title or text search