Index: > A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Business Industries Finance Tax

Home > Polymorphism (computer science)


First Prev [ 1 2 3 ] Next Last

In computer science, polymorphism is the idea of allowing the same code to be used with different types, resulting in more general and abstract implementations.

The concept of polymorphism applies to functions as well as types:

There are two fundamentally different kinds of polymorphism:

Programming using the latter kind is called generic programming, particularly in the object-oriented community. However, in many statically typed functional programming languages the notion of parametric polymorphism is so deeply ingrained that most programmers simply take it for granted.

Polymorphism gained most of its momentum when object-oriented programming became a buzzword.

1 Parametric polymorphism

Using parametric polymorphism, a function or datatype can be written generically so that it can deal equally well with objects of various types. For example, a function append that joins two lists can be constructed so that it does not depend on one particular type of list: it can append lists of integers, lists of real numbers, lists of strings, and so on. Let a denote the type of elements in the lists. Then append can be typed [a] × [a] → [a], where [a] denotes a list of elements of type a. We say that append is parameterized by a. (Note that since there is only one type parameter, the function cannot be applied to just any pair of lists: they must consist of the same type of elements.)

Parametric polymorphism was the first type of polymorphism developed, first identified by Christopher Strachey in 1967. It was also the first type of polymorphism to appear in an actual programming language, ML in 19761976 is a leap year starting on Thursday (link will take you to calendar). Events January January 12 UN Security Council votes 11-1 to admit the Palestinian Liberation Organization January 15 Would-be Gerald Ford presidential assassin Sara Jane Moore is s. It exists today in Standard ML, O'Caml, HaskellHaskell is a standardized functional programming language with non-strict semantics, named after the logician Haskell Curry. It was created by a committee formed in the 1980s for the express purpose of defining such a language. The latest semi-official la, and others. Some argue that templates should be considered an example of parametric polymorphism, though instead of actually reusing generic code they rely on macros to generate specific code (which can result in code bloat ).

Parametric polymorphism is a way to make a language more expressible, while still maintaining full static type-safety. It is thus irrelevant in dynamically typedOne major distinction made in the nature and behaviour of programming languages is that of its typing. In statically typed programming languages, every program expression is assigned a type before program execution; usually, it is sufficient to assign a t languages, since by definition they lack static type-safety. However, any dynamically typed function f that takes n arguments can be given a static type using parametric polymorphism: f : p1 × ... × pn → r, where p1, ..., pn and r are type parameters. Of course, this type is completely insubstantial and thus essentially useless.





Non User