ArticleslgStudy

computer science

Row polymorphism

Row polymorphism is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Row polymorphism rather than just read about it. In short: In programming language type theory, row polymorphism is a kind of polymorphism that allows one to write programs that are structurally (rather than nominally) polymorphic on record types and/or variants. History Row types and row polymorphism were introduced by Mitchell Wand in the late 1980s as an approach to structurally typing extensible records and variants.

Key takeaways

  • Row polymorphism belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Row polymorphism to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Row polymorphism from memory before moving on to harder problems.

Reference excerpt

In programming language type theory, row polymorphism is a kind of polymorphism that allows one to write programs that are structurally (rather than nominally) polymorphic on record types and/or variants.

History Row types and row polymorphism were introduced by Mitchell Wand in the late 1980s as an approach to structurally typing extensible records and variants. The principal motivation for rows (and other structural typing paradigms of that time, most notably subtyping relatons) was to safely type emerging object-oriented patterns for object inheritance and extension. More specifically, Wand defined row types in order to model complete type inference for multiple inheritance of objects. As observed by Rémy, Wand's original type inference algorithm was not complete due to an ambiguity in overlap resolution, which was later corrected by both Rémy and Wand. Wand's original system permitted records to be constructed only by extension (that is, one field at a time), but would later show that type inference remains decidable in the presence of record concatenation, albeit without principal types. While Wand and Remy's initial row type systems supported variant construction, the bulk of attention focused on record extensibility. Gaster and Jones give a more uniform treatment and additionally introduce type constraints on row variables to specify row equality. In contrast to Remy's presence polymorphism, they likewise use the language of qualified types to specify label presence via a lacks predicate. Blume et al. take the approach one step further into the realm of composable extensions by adding "first-class cases" handled by a LetCC construct to compose continuations in the case-matching code. In the modern day, row types are most commonly used to type extensible algebraic effects. For example, (Links, Koka) have used row polymorphism as the type basis of an algebraic effects system, aiming for "free composition" of user-defined effects. Morris and McKinna generalized row types to partial monoids, dubbed row theories, to uniformly handle varying notions of record and variant-eliminator concatenation in a single theoretical framework. For instance, one application may desire concatenation to overwrite existing fields in case of overlapping labels, while another may want to keep both of them accessible (and have one label scope the other). Their system Rose abstracts over arbitrary row theories, where the particular resolution of label overlaps is subject to the meaning of a row combination predicate, ρ1⊕ρ2∼ρ3, which is satisfied precisely when the combination of rows ρ1 and ρ2 is both (1) well-defined and (2) equal to ρ3. This predicate need not be satisfiable in all cases (hence the monoid is partial). For example, it is not always satisfied in row theories barring label overlap. The authors show that type inference remains decidable for their system.

Theory Row type systems vary by author and have no universally accepted criteria, however it is generally accepted that a row system should at minimum permit rows and (at least one of) record and variant types. Formally, a row is an association of labels to types. When constructing a record, the labels of a row refer to the accessor (or, destructor) names, while the types in the row refer to the output types. For example, a two-dimensional point may be specified by the row row Point={x:Int,y:Int} and a record is constructed via the application of the type operator Π (for product) to this row: p:ΠPoint p=(x:=1,y:=2) Dually, when constructing a variant, the labels of a row refer to constructor names, and the types of a row refer to the input types. The Bool type is a simple variant, with constructors true and false and nullary input, as captured by the following row: row Bool={True:⊤,False:⊤} (We use the unit type ⊤ to simulate nullary constructors.) The type constructor Σ (for sum) constructs the Boolean variant. Variants are most typically constructed by injection, which can be expressed either explicitly (as done so below) or implicitly (via a subtyping relation and implicit coercions). true:ΣBool true=inj(True=tt) Row polymorphism refers specifically to the quantification of row type variables, which can be specified via a kind system when necessary. For example, record projection is defined polymorphically over rows ρ1 and ρ2 subject to the condition that the output record (constructed via Πρ1) has a subset of the fields in the input record of type Πρ2. prj:ρ1≤ρ2⇒Πρ2→Πρ1 (The syntax above presumes a qualified type system, in which the predicate ρ1≤ρ2 constrains the type instantiations of the row variable ρ1 to just rows that contain a subset of fields in (the instantiation of) row variable ρ2). Dually, variant injection is defined polymorphically over rows ρ1 and ρ2 subject to the condition that the input variant (constructed via ρ1) has a subset of the fields in the output variant (constructed via ρ2). inj:ρ1≤ρ2⇒Σρ1→Σρ2 The theoretical treatment of row polymorphism is somewhat complicated by the need to have distinct labels in a record. One approach, taken by Rémy and colleagues (and implicitly present in the presentation below, which is heavily inspired by Wand's), is to consider different kinds of row types, depending on their labels.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Row polymorphism

Start with the simplest possible case. Write down what Row polymorphism claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Row polymorphism before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Row polymorphism ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Row polymorphism

In research
Row polymorphism appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Row polymorphism in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Row polymorphism is common in secondary-school and first-year university syllabi. It links to neighbouring topics Polymorphism (computer science), so understanding it makes those chapters shorter.
In everyday life
Look for Row polymorphism outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Row polymorphism” →

How to study Row polymorphism in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Row polymorphism means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Row polymorphism out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Row polymorphism in simple terms?

In programming language type theory, row polymorphism is a kind of polymorphism that allows one to write programs that are structurally (rather than nominally) polymorphic on record types and/or variants. History Row types and row polymorphism were introduced by Mitchell Wand in the late 1980s as a…

Why does Row polymorphism matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Row polymorphism?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Row polymorphism.

Tags

  • Polymorphism (computer science)

Keep exploring