Reference articles on history, science, culture and more
Encyclopedia

Refinement type

Types constrained by a predicate

In type theory, a refinement type is a type endowed with a predicate which is assumed to hold for any element of the refined type. Refinement types can express preconditions when used as function arguments or postconditions when used as return types: for instance, the type of a function which accepts natural numbers and returns natural numbers greater than 5 may be written as f:\mathbb {N} \rightarrow \{n\in \mathbb {N} \,|\,n>5\}. Refinement types are thus related to behavioral subtyping.

01History

The concept of refinement types was first introduced in Freeman and Pfenning's 1991 Refinement types for ML, which presents a type system for a subset of Standard ML. The type system "preserves the decidability of ML's type inference" whilst still "allowing more errors to be detected at compile-time". In more recent times, refinement type systems have been developed (primary in academia) for languages such as Haskell, TypeScript, Rust, and as libraries for real world usage in Scala.

Watch videos about Refinement typeExplainers and documentaries on YouTube (opens in a new tab)

Sources and credits

This article is adapted from the Wikipedia article Refinement type, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.

Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.