请输入您要查询的百科知识:

 

词条 Substructural type system
释义

  1. Different substructural type systems

      Linear type systems    Affine type systems    Relevant type system    Ordered type system  

  2. Programming languages

  3. See also

  4. Notes

  5. References

{{One source|date=February 2018}}{{Type systems}}

Substructural type systems are a family of type systems analogous to substructural logics where one or more of the structural rules are absent or only allowed under controlled circumstances. Such systems are useful for constraining access to system resources such as files, locks and memory by keeping track of changes of state that occur and preventing invalid states.{{sfn|Walker|2002|p=X}}{{sfn|Walker|2002|p=4}}

Different substructural type systems

Several type systems have emerged by discarding some of the structural rules of exchange, weakening, and contraction:

exchangeweakeningcontractionuse
linearallowedexactly once
affineallowedallowedat most once
relevantallowedallowedat least once
orderedexactly once in order
  • 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.
  • Ordered type systems (discard exchange, contraction, and weakening): Every variable is used exactly once in the order it was introduced.

The explanation for affine type systems is best understood if rephrased as “every occurrence of a variable is used at most once”.

Linear type systems

Linear types corresponds to linear logic and ensures that objects are used exactly once, allowing the system to safely deallocate an object after its use.{{sfn|Walker|2002|p=6}}

The Clean programming language makes use of uniqueness types (a variant of linear types) to help support concurrency, input/output, and in-place update of arrays.{{sfn|Walker|2002|p=43}}

Linear type systems allow references but not aliases. To enforce this, a reference goes out of scope 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 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 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.[1]

The single-reference property makes linear type systems suitable as programming languages for quantum computation, as it reflects the no-cloning theorem of quantum states. From the category theory point of view, no-cloning is a statement that there is no diagonal functor which could duplicate states; similarly, from the combinator point of view, there is no K-combinator which can destroy states. From the lambda calculus point of view, a variable x can appear exactly once in a term.[2]

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. More precisely, one may construct functors between the category of linear type systems and the category of closed symmetric monoidal categories.[3]

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 only be used once, while a linear one must be used 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.

Ordered type system

Ordered types correspond to noncommutative logic 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).{{sfn|Walker|2002|pp=30–31}} 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.

Programming languages

The following programming languages support linear or affine types:

  • ATS
  • Clean
  • Idris
  • Mercury
  • Rust
  • F
  • [https://github.com/pikatchu/LinearML LinearML]
  • Alms
  • [https://arxiv.org/abs/1710.09756 Linear Haskell]

See also

  • Effect system
  • Linear logic
  • Affine logic

Notes

1. ^std::unique_ptr reference
2. ^John c. Baez and Mike Stay, "Physics, Topology, Logic and Computation: A Rosetta Stone", (2009) [https://arxiv.org/abs/0903.0340/ ArXiv 0903.0340] in New Structures for Physics, ed. Bob Coecke, Lecture Notes in Physics vol. 813, Springer, Berlin, 2011, pp. 95-174.
3. ^S. Ambler, "First order logic in symmetric monoidal closed categories", Ph.D. thesis, U. of Edinburgh, 1991.

References

  • {{cite book|first=David|last=Walker|authorlink=David Walker (computer scientist)|editor1-first=Benjamin C.|editor1-last=Pierce|editor1-link=Benjamin C. Pierce|year=2002|title=Advanced Topics in Types and Programming Languages|publisher=MIT Press|isbn=0-262-16228-8 | ref = harv | chapter = Substructural Type Systems | pages = 3–43}}

1 : Type theory

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/16 14:15:50