类型理论
Substructural type system
这是维基百科的介绍。但是里面好多专有名词,在网上找到一些定义的介绍,参考
From Wikipedia, the free encyclopedia
Jump to navigationJump to search
This article relies largely or entirely on a single source. Relevant discussion may be found on the talk page. Please help improve this article by introducing citations to additional sources. Find sources: “Substructural type system” – news · newspapers · books · scholar · JSTOR (February 2018) | |
---|---|
Type systems |
---|
General concepts |
Type safetyStrong vs. weak typing |
Major categories |
Static vs. dynamicManifest vs. inferredNominal vs. structuralDuck typing |
Minor categories |
AbstractDependentFlow-sensitiveGradualIntersectionLatentRefinementSubstructuralUniqueSession |
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.[1][2]
Contents
- 1Different substructural type systems
- 2Programming languages
- 3See also
- 4Notes
- 5References
Different substructural type systems[edit]
Several type systems have emerged by discarding some of the structural rules of exchange, weakening, and contraction:
Exchange | Weakening | Contraction | Use | |
---|---|---|---|---|
Ordered | — | — | — | Exactly once in order |
Linear | Allowed | — | — | Exactly once |
Affine | Allowed | Allowed | — | At most once |
Relevant | Allowed | — | Allowed | At least once |
Normal | Allowed | Allowed | Allowed | Arbitrarily |
- 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[edit]
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).[3] 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[edit]
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.[4]
线性类型对应于线性逻辑并确保对象只使用一次,从而允许系统在使用后安全地释放对象。[4]
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.[5]
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.[6]
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.[7]
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.[8]
Affine type systems[edit]
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[edit]
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[edit]
The following programming languages support linear or affine types:
- ATS
- Clean
- Idris
- Mercury
- Rust
- [F](https://en.wikipedia.org/wiki/F_(programming_language))
- LinearML
- Alms
- Haskell with GHC 9.0 or above
- Granule
See also[edit]
Notes[edit]
- [^](https://en.wikipedia.org/wiki/Substructural_type_system#cite_ref-FOOTNOTEWalker2002X_1-0) Walker 2002, p. X.
- [^](https://en.wikipedia.org/wiki/Substructural_type_system#cite_ref-FOOTNOTEWalker20024_2-0) Walker 2002, p. 4.
- [^](https://en.wikipedia.org/wiki/Substructural_type_system#cite_ref-FOOTNOTEWalker200230–31_3-0) Walker 2002, pp. 30–31.
- [^](https://en.wikipedia.org/wiki/Substructural_type_system#cite_ref-FOOTNOTEWalker20026_4-0) Walker 2002, p. 6.
- [^](https://en.wikipedia.org/wiki/Substructural_type_system#cite_ref-FOOTNOTEWalker200243_5-0) Walker 2002, p. 43.
- [^](https://en.wikipedia.org/wiki/Substructural_type_system#cite_ref-6) std::unique_ptr reference
- [^](https://en.wikipedia.org/wiki/Substructural_type_system#cite_ref-7) John c. Baez and Mike Stay, “Physics, Topology, Logic and Computation: A Rosetta Stone”, (2009) ArXiv 0903.0340 in New Structures for Physics, ed. Bob Coecke, Lecture Notes in Physics vol. 813, Springer, Berlin, 2011, pp. 95-174.
- [^](https://en.wikipedia.org/wiki/Substructural_type_system#cite_ref-8) S. Ambler, “First order logic in symmetric monoidal closed categories”, Ph.D. thesis, U. of Edinburgh, 1991.
References[edit]
- Walker, David (2002). “Substructural Type Systems”. In Pierce, Benjamin C. (ed.). Advanced Topics in Types and Programming Languages (PDF). MIT Press. pp. 3–43. ISBN 0-262-16228-8.
学校的课程
https://groups.seas.harvard.edu/courses/cs152/2021sp/
Course information
This course is an introduction to the theory, design, and implementation of programming languages. Topics covered in this course include: formal semantics of programming languages (operational, axiomatic, denotational, and translational), type systems, higher-order functions and lambda calculus, laziness, continuations, dynamic types, monads, objects, modules, concurrency, and communication.
本课程介绍编程语言的理论、设计和实现。 本课程涵盖的主题包括:编程语言的形式语义(操作、公理、指称和翻译)、类型系统、高阶函数和 lambda 演算、惰性、延续、动态类型、单子、对象、模块、并发性和 沟通。
See the lecture schedule for more detailed information on topics covered.
Resources
Text books
A number of excellent books and on-line resources overlap with the course’s content and can provide alternate explanations despite differences in notation and approach. Let the instructor know if you have trouble finding the intersection between these resources and the course content.
- “Types and Programming Languages” by Benjamin C. Pierce, MIT Press, 2002. Available on reserve at the library.
- “Software Foundations” by Benjamin C. Pierce et al., Volume 1: Logical Foundations and Volume 2: Programming Language Foundations. Available as literate Coq files. Also available as literate Agda files thanks to Philip Wadler, Wen Kokke and Jeremy Siek.
- “Practical Foundations for Programming Languages” by Robert Harper, Cambridge University Press, 2013. Draft available on Harper’s website.
- “Concepts in Programming Languages” by John C. Mitchell, Cambridge University Press, 2003. Available online through Harvard University Libraries eContent Collection.
- “The Formal Semantics of Programming Languages” by Glynn Winskel, MIT Press, 1993. Available on reserve at the library.
- “Programming Languages: Application and Interpretation” by Shriram Krishnamurthi. There are two editions, both available on the author’s website: http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/.
OCaml resources
-
Installation: https://ocaml.org/docs/install.html
-
Tools:
https://github.com/realworldocaml/book/wiki/Installation-Instructions
This link gives instructions for installing things like Tuareg (a useful emacs mode) and Merlin (advanced IDE features).
Installing Tuareg is pretty simple and will make your OCaml coding experience a lot nicer (though it’s of course not necessary). Merlin is probably overkill unless you know what you’re doing.
-
Learning:
-
Standard library documentation:
http://caml.inria.fr/pub/docs/manual-ocaml/libref/index.html
The following documentation may be particularly useful as you work on your assignments.
- Sets: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Set.Make.html
- Maps: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Map.Make.html
-
Everything you need to know and more: http://caml.inria.fr/pub/docs/manual-ocaml/index.html
-
Code examples: http://ocaml.org/learn/tutorials/99problems.html
-
See also the CS51 Resources web page for OCaml books, references, and tutorials.
Coq resources
- Download Coq.
- Coq includes an IDE, CoqIDE. Alternatively, with Emacs, you can use Proof General.
- Coq documentation.
Dafny resources
Haskell resources
- Download The Haskell Platform.
- List of Haskell tutorials. If you want to get more meta, see How to Learn Haskell.
- haskell.org contains lots of reference information, language specification, etc.
lectures
NOTE: The current schedule is tentative and subject to change. Nonetheless it gives an idea of the material to be covered in this course. The lecture notes are seeded from previous years, and will be sporadically updated.
Key to readings: P = Pierce; SF = Software Foundations; M = Mitchell; W = Winskel; K = Krishnamurthi 1st ed.; K2nd = Krishnamurthi 2nd ed.; H = Harper. The readings are not required, but may help your understanding of the lecture material.
The lecture notes here contain material from lecture notes by Stephen Chong, Radu Rugina, Andrew Myers, Nate Foster, and Jeff Vaughan.
Videos of the lecture and sections are available on Canvas. The same site also provides a Zoom link for live streaming of and remote participation in lectures.
For background material on sets, relations, functions, and induction, see: W 1, H 2, H Appendix, and/or P 2.
Lec. | Date | Topic | Readings | Notes | Slides | Code | Assignments |
---|---|---|---|---|---|---|---|
Semantics | |||||||
1 | Tue 26-Jan | Intro to semantics, Proof tools | P 2.4, 3 SF1-Induction,Imp SF2-SmallStep W 2,3,4 H 2 | OCaml Coq | |||
2 | Thu 28-Jan | Small-step semantics | Coq | ||||
3 | Tue 2-Feb | Induction | Coq | Assignment 1 released | |||
4 | Thu 4-Feb | Large-step semantics | Coq | ||||
5 | Tue 9-Feb | IMP: a simple imperative language | Coq | ||||
6 | Thu 11-Feb | Denotational semantics | W 5 M 4.3 | ||||
Lambda calculus | |||||||
7 | Tue 16-Feb | Lambda calculus | P 5 M 4.2 K 22 | ||||
8 | Thu 18-Feb | Lambda calculus encodings and Recursion | |||||
9 | Tue 23-Feb | Definitional translations | |||||
10 | Thu 25-Feb | References and continuations | P 13 M 5,4, 8.3.2 H 29, 36 K 18-20 | Assignment 1 due Assignment 2 released | |||
Types | |||||||
11 | Tue 2-Mar | Simply-typed lambda calculus Type soundness | P 9 SF2-Stlc SF2-StlcProp M 6.1, 6.2 K 24-26(P 12) (SF2-Norm) | ||||
13 | Thu 4-Mar | More types | P 11, 13 SF2-MoreStlc SF2-References | ||||
12 | Tue 9-Mar | NO CLASS MIDTERM | |||||
14 | Thu 11-Mar | Parameteric Polymorphism, Records and Subtyping | P 23 M 6.4 P 11.8, 15 | Assignment 3 released | |||
No Class | |||||||
15 | Thu 18-Mar | Curry-Howard isomorphism; Existential types | P 9.4 SF1-ProofObjects | Haskell | Assignment 2 due | ||
16 | Tue 23-Mar | Type Inference | P 22 K30 | Prolog | |||
17 | Thu 25-Mar | Sub-structural type systems | eg1.rs eg2.rs eg3.rs eg4.rs eg5.rs | Assignment 3 due Assignment 4 released | |||
18 | Tue 30-Mar | Algebraic structures | m.hs agediff.hs io.hs state.hs | ||||
Reasoning About Programs | |||||||
19 | Thu 1-Apr | Axiomatic Semantics and Hoare Logic | SF2-Hoare W 6 (W 7) | hoare.c hoare.dfy factorial.c factorial.dfy | |||
20 | Tue 6-Apr | Dependent types | Twelf | ||||
0 | Thu 8-Apr | Embedded EthiCS: Specifications of Ethical Concerns | Assignment 4 due Assignment 5 released | ||||
Misc. Topics | |||||||
21 | Tue 13-Apr | Logic Programming (Guest appearance: Will Byrd) | M 15 K32-34 | ||||
No Class | |||||||
22 | Tue 20-Apr | Probabilistic Programming (Guest lecturer: Yizhou Zhang) | |||||
25 | Thu 22-Apr | Semantics for Verified Software-Hardware Stacks (Guest lecturer: Samuel Gruetter) | Assignment 5 due Assignment 6 released | ||||
24 | Tue 27-Apr | Concurrency | M 14 | ex1.go ex2.go ex3.go | |||
Thu 29-Apr | Assignment 6 due | ||||||
TBD TBD-May | FINAL EXAM: TBD |
- 上一篇 Rustdesk支持httpproxy之努力1
- 下一篇 浏览器的密码安全