Jump to content

Row polymorphism

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ramunasg (talk | contribs) at 11:16, 25 October 2018 (Created page with 'In programming language type theory, row polymorphism is a kind of polymorphism that allows to write programs that a...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

In programming language type theory, row polymorphism is a kind of polymorphism that allows to write programs that are polymorphic on record field types (also known as rows, hence row polymorphism). A row-polymorphic type system and proof of type inference was introduced by Mitchel Wand.[1][2]

Records and Record Types

A record value is written as where the record contains n field (rows), are the record fields and field values. For example, a record containing a three-dimensional cartesian point could be written as .

The row-polymorphic record type is written as . A record has the row-polymorphic record type whenever the fields of the record have the type and does not have the fields . The row-polymorphic variable expresses the fact the the record may contain other fields than .

The row-polymorphic record types allows as to write programs that operate only on a section of a record. For example, is a function that performs some two dimensional transformation. Because we are use row-polymorphism, the function may perform two-dimensional transformation on a three-dimensional (in fact, n-dimensional) point leaving the z coordinate intact. In fact, the function can perform on any record that contains the fields and with type . Note that we did not loose any information, the type ensures that all the fields represented by the variable are present in the return type.

The row polymorphims may be constrained. The type expresses the fact that a record of that type has exactly the and fields and nothing else. Thus, a classic record type is obtained.

Typing operations on records

The record operations of selecting a field , adding a field, and removing a field can be given row-polymorhic types.


Notes

  1. ^ Wand, Mitchell (June 1989). "Type inference for record concatenation and multiple inheritance". Proceedings. Fourth Annual Symposium on Logic in Computer Science. pp. 92–97. doi:10.1109/LICS.1989.39162.
  2. ^ Wand, Mitchell (1991). "Type inference for record concatenation and multiple inheritance". Information and Computation. 93 (Selections from 1989 IEEE Symposium on Logic in Computer Science): 1–15. doi:10.1016/0890-5401(91)90050-C. ISSN 0890-5401.