encyclopegia.org

Value restriction

In programming languages with Hindley–Milner type inference and imperative features, in particular the ML programming language family, the value restriction means that declarations are only polymorphically generalized if they are syntactic values (also called non-expansive). The value restriction prevents reference cells from holding values of different types and preserves type safety.

In programming languages with Hindley–Milner type inference and imperative features, in particular the ML programming language family, the value restriction means that declarations are only polymorphically generalized if they are syntactic values (also called non-expansive). The value restriction prevents reference cells from holding values of different types and preserves type safety. \mathtt{:=} &: \forall \alpha . (\alpha\ \mathtt{ref}) \to \alpha \to \mathtt{unit} \end{align} The operators have the following semantics: \mathtt{ref} takes a value and creates a reference containing that value, \mathtt{!} (dereference) takes a reference and reads the value in that reference, and \mathtt{:=} (assignment) updates a reference to contain a new value and returns a value of the unit type. Given these, the following program unsoundly applies a function meant for integers to a Boolean value. let val c = ref (fn x => x) in c := (fn x => x + 1); !c true end The above program type checks using Hindley-Milner because c is given the type \forall \alpha . (\alpha \to \alpha)\ \mathtt{ref} , which is then instantiated to be of the type (\mathtt{int} \to \mathtt{int})\ \mathtt{ref} when typing the assignment c := (fn x => x + 1) , and (\mathtt{bool} \to \mathtt{bool})\ \mathtt{ref} ref when typing the dereference !c true . Under the value restriction, the types of let bound expressions are only generalized if the expressions are syntactic values. In his paper, Wright considers the following to be syntactic values: constants, variables, \lambda -expressions and constructors applied to values. The function and operator applications are not considered values. In particular, applications of the \mathtt{ref} operator are not generalized. It is safe to generalize type variables of syntactic values because their evaluation cannot cause any side-effects such as writing to a reference. The above example is rejected by the type checker under the value restriction as follows. First c is given the type (\alpha \to \alpha)\ \mathtt{ref} . This type is not generalized and \alpha is a free variable in the typing context for the body of the let binding. When the assignment is typed, the type of c is modified in the typing context to be of type (\mathtt{int} \to \mathtt{int})\ \mathtt{ref} via unification. The dereference !c is typed as \mathtt{int} \to \mathtt{int} , but is applied to a value of type \mathtt{bool} , and the type checker rejects the program. Andrew Wright (1995). "Simple imperative polymorphism". In LISP and Symbolic Computation, p. 343–356. Jacques Garrigue (2004). "Relaxing the Value Restriction".

References

No reference rows published for this article.

Cite this article

MLA

"Value restriction." encyclopegia.org, 2025, https://encyclopegia.org/wiki/value-restriction. Accessed 25 November 2026.

Chicago

"Value restriction." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/value-restriction.

APA

encyclopegia.org. (2025). Value restriction. Retrieved November 25, 2026, from https://encyclopegia.org/wiki/value-restriction

Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

half-value thickness

stub · references available

truth value

stub · references available

mean value theorem

stub · references available

restriction enzyme

stub · references available

default value

stub · references available

sign-value numeral system

stub · references available

replacement value

stub · references available

market value of real property

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1292239599 · 0.5 · snapshot enwiki-001292239599

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.