Parameterizing over types

A function that swaps two values need not be rewritten for integers, strings, and every other type. Type parameters describe the input types and how the output preserves their relationships. One algorithm can then serve different concrete types while type checking still constrains the inputs and result of each use.

References: [1]

Generality with consistency

A type variable represents an unspecified type, but all corresponding occurrences must agree within an instantiation. A function promising to return its unchanged input cannot simply turn an integer into a string. Parametric generality preserves relationships across types rather than abandoning constraints and allowing every possible input-output combination.

References: [1]

Parameterizing data structures

A list type can take an element-type parameter, yielding integer lists, string lists, and other instances. Computing length only traverses structure, whereas summing elements requires an appropriate operation. A parameterized list does not by itself permit every position in one list to contain a value of an unrelated type.

References: [1]

Why mutable state constrains generality

A function retaining mutable state can connect otherwise separate calls. OCaml’s value restriction and weak type variables prevent shared storage from being reused at incompatible types. The permitted generality therefore depends on how the type system handles effects, not merely on whether the programmer omitted explicit annotations.

References: [2]