Parametricity

In programming language theory, parametricity is an abstract uniformity property enjoyed by parametrically polymorphic functions, which captures the intuition that all instances of a polymorphic function act the same way.

Idea

Consider this example, based on a set X and the type T(X) = [XX] of functions from X to itself. The higher-order function twiceX : T(X) → T(X) given by twiceX(f) = ff, is intuitively independent of the set X. The family of all such functions twiceX, parametrized by sets X, is called a "parametrically polymorphic function". We simply write twice for the entire family of these functions and write its type as X. T(X) → T(X). The individual functions twiceX are called the components or instances of the polymorphic function. Notice that all the component functions twiceX act "the same way" because they are given by the same rule. Other families of functions obtained by picking one arbitrary function from each T(X) → T(X) would not have such uniformity. They are called "ad hoc polymorphic functions". Parametricity is the abstract property enjoyed by the uniformly acting families such as twice, which distinguishes them from ad hoc families. With an adequate formalization of parametricity, it is possible to prove that the parametrically polymorphic functions of type X. T(X) → T(X) are one-to-one with natural numbers. The function corresponding to the natural number n is given by the rule f fn, i.e., the polymorphic Church numeral for n. In contrast, the collection of all ad hoc families would be too large to be a set.

History

The parametricity theorem was originally stated by John C. Reynolds, who called it the abstraction theorem.[1] In his paper "Theorems for free!",[2] Philip Wadler described an application of parametricity to derive theorems about parametrically polymorphic functions based on their types.

Programming language implementation

Parametricity is the basis for many program transformations implemented in compilers for the programming language Haskell. These transformations were traditionally thought to be correct in Haskell because of Haskell's non-strict semantics. Despite being a lazy evaluation programming language, Haskell does support certain primitive operations, such as the operator seq—that enable so-called selective strictness, allowing evaluation to be forced for certain expressions. In their paper "Free theorems in the presence of seq",[3] Patricia Johann and Janis Voigtlaender showed that because of the presence of these operations, the general parametricity theorem does not hold for Haskell programs; thus, these transformations are unsound in general.

Dependent types

See also

References

  1. ^ Reynolds, J.C. (1983). "Types, abstraction, and parametric polymorphism" (PDF). Information Processing. North Holland, Amsterdam. pp. 513–523.
  2. ^ Wadler, Philip (September 1989). "Theorems for free!". 4th International Conference on Functional Programming and Computer Architecture. London.
  3. ^ Johann, Patricia; Voigtlaender, Janis (January 2004). "Free theorems in the presence of seq". Proceedings, Principles of Programming Languages. pp. 99–110. doi:10.1145/964001.964010.

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.