Substructural type systems are a family of
type systems analogous to
substructural logics where one or more of the
structural rule
In proof theory, a structural rule is an inference rule that does not refer to any logical connective, but instead operates on the judgment or sequents directly. Structural rules often mimic intended meta-theoretic properties of the logic. Logics ...
s are absent or only allowed under controlled circumstances. Such systems are useful for constraining access to
system resource
In computing, a system resource, or simple resource, is any physical or virtual component of limited availability within a computer system. All connected devices and internal system components are resources. Virtual system resources include fi ...
s such as
files
File or filing may refer to:
Mechanical tools and processes
* File (tool), a tool used to ''remove'' fine amounts of material from a workpiece
**Filing (metalworking), a material removal process in manufacturing
** Nail file, a tool used to gent ...
,
locks and
memory by keeping track of changes of state that occur and preventing invalid states.
Different substructural type systems
Several type systems have emerged by discarding some of the
structural rules of exchange, weakening, and contraction:
*Ordered type systems (discard exchange, weakening and contraction): Every variable is used exactly once in the order it was introduced.
*Linear type systems (allow exchange, but neither weakening nor contraction): Every variable is used exactly once.
*Affine type systems (allow exchange and weakening, but not contraction): Every variable is used at most once.
*Relevant type systems (allow exchange and contraction, but not weakening): Every variable is used at least once.
*Normal type systems (allow exchange, weakening and contraction): Every variable may be used arbitrarily.
The explanation for affine type systems is best understood if rephrased as “every ''occurrence'' of a variable is used at most once”.
Ordered type system
Ordered types correspond to
noncommutative logic Noncommutative logic is an extension of linear logic which combines the commutative connectives of linear logic with the noncommutative multiplicative connectives of the Lambek calculus. Its sequent calculus relies on the structure of order varietie ...
where exchange, contraction and weakening are discarded. This can be used to model
stack-based memory allocation (contrast with linear types which can be used to model heap-based memory allocation). Without the exchange property, an object may only be used when at the top of the modelled stack, after which it is popped off resulting in every variable being used exactly once in the order it was introduced.
Linear type systems
Linear types corresponds to
linear logic
Linear logic is a substructural logic proposed by Jean-Yves Girard as a refinement of classical and intuitionistic logic, joining the dualities of the former with many of the constructive properties of the latter. Although the logic has also be ...
and ensures that objects are used exactly once. This allows the system to safely
deallocate an object after its use, or to design
software interfaces that guarantee a resource cannot be used once it has been closed or transitioned to a different state.
The
Clean programming language
Clean is a general-purpose purely functional computer programming language. It was called the Concurrent Clean System, then the Clean System, later just Clean. Clean has been developed by a group of researchers from the Radboud University in Nij ...
makes use of
uniqueness types (a variant of linear types) to help support concurrency,
input/output, and in-place update of arrays.
Linear type systems allow
references but not
aliases. To enforce this, a reference goes out of
scope
Scope or scopes may refer to:
People with the surname
* Jamie Scope (born 1986), English footballer
* John T. Scopes (1900–1970), central figure in the Scopes Trial regarding the teaching of evolution
Arts, media, and entertainment
* CinemaS ...
after appearing on the right-hand side of an
assignment, thus ensuring that only one reference to any object exists at once. Note that passing a reference as an
argument
An argument is a statement or group of statements called premises intended to determine the degree of truth or acceptability of another statement called conclusion. Arguments can be studied from three main perspectives: the logical, the dialectic ...
to a
function is a form of assignment, as the function parameter will be assigned the value inside the function, and therefore such use of a reference also causes it to go out of scope.
A linear type system is similar to
C++'s
unique_ptr
In computer science, a smart pointer is an abstract data type that simulates a Pointer (computer programming), pointer while providing added features, such as automatic memory management or bounds checking. Such features are intended to reduce bu ...
class, which behaves like a pointer but can only be moved (i.e. not copied) in an assignment. Although the linearity constraint is checked at
compile time, dereferencing an invalidated unique_ptr causes undefined behavior at
run-time. Similarly, the
Rust programming language has partial support to linear types through the use of lint annotations but differently from C++ the moved from variable cannot be used again.
The single-reference property makes linear type systems suitable as programming languages for
quantum computation
Quantum computing is a type of computation whose operations can harness the phenomena of quantum mechanics, such as superposition, interference, and entanglement. Devices that perform quantum computations are known as quantum computers. Though ...
, as it reflects the
no-cloning theorem of quantum states. From the
category theory
Category theory is a general theory of mathematical structures and their relations that was introduced by Samuel Eilenberg and Saunders Mac Lane in the middle of the 20th century in their foundational work on algebraic topology. Nowadays, cate ...
point of view, no-cloning is a statement that there is no
diagonal functor which could duplicate states; similarly, from the
combinatory logic
Combinatory logic is a notation to eliminate the need for quantified variables in mathematical logic. It was introduced by Moses Schönfinkel and Haskell Curry, and has more recently been used in computer science as a theoretical model of comput ...
point of view, there is no K-combinator which can destroy states. From the
lambda calculus
Lambda calculus (also written as ''λ''-calculus) is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. It is a universal model of computation ...
point of view, a variable ''x'' can appear exactly once in a term.
Linear type systems are the
internal language of
closed symmetric monoidal categories, much in the same way that
simply typed lambda calculus is the language of
Cartesian closed categories
In category theory, a category is Cartesian closed if, roughly speaking, any morphism defined on a product of two objects can be naturally identified with a morphism defined on one of the factors. These categories are particularly important in ma ...
. More precisely, one may construct
functors between the category of linear type systems and the category of closed symmetric monoidal categories.
Affine type systems
Affine types are a version of linear types allowing to ''discard'' (i.e. ''not use'') a resource, corresponding to
affine logic. An affine resource ''can'' be used ''at most'' once, while a linear one ''must'' be used ''exactly'' once.
Relevant type system
Relevant types correspond to
relevant logic which allows exchange and contraction, but not weakening, which translates to every variable being used at least once.
Programming languages
The following programming languages support linear or affine types:
*
C++
*
ATS
ATS or Ats may refer to:
Businesses
* ATS Wheels, or ''Auto Technisches Spezialzubehör'', a German wheel manufacturer and sponsor of a Formula One racing team
* ATS Automation Tooling Systems, an Ontario, Canada-based factory automation company
...
*
Clean
*
Idris Idris may refer to:
People
* Idris (name), a list of people and fictional characters with the given name or surname
* Idris (prophet), Islamic prophet in the Qur'an, traditionally identified with Enoch, an ancestor of Noah in the Bible
* Idris G ...
*
Mercury
Mercury commonly refers to:
* Mercury (planet), the nearest planet to the Sun
* Mercury (element), a metallic chemical element with the symbol Hg
* Mercury (mythology), a Roman god
Mercury or The Mercury may also refer to:
Companies
* Merc ...
*
F*
LinearMLAlms*
Haskell with
GHC 9.0.1 or above.
Linear types
/ref>
Granule
* Rust
* Nim
Nim is a mathematical two player game.
Nim or NIM may also refer to:
* Nim (programming language)
* Nim Chimpsky, a signing chimpanzee Acronyms
* Network Installation Manager, an IBM framework
* Nuclear Instrumentation Module
* Negative index met ...
See also
* Effect system
* Linear logic
Linear logic is a substructural logic proposed by Jean-Yves Girard as a refinement of classical and intuitionistic logic, joining the dualities of the former with many of the constructive properties of the latter. Although the logic has also be ...
* Affine logic
Notes
References
*
*
*
* {{cite book , last1=Baez , first1=John C. , last2=Stay , first2=Mike , url=http://math.ucr.edu/home/baez/rosetta/rose3.pdf , chapter=Physics, Topology, Logic and Computation: A Rosetta Stone , date=2010 , title=New Structures for Physics , editor=Springer , pages=95–174
Type theory