词条 | Uniqueness type |
释义 |
In computing, a unique type guarantees that an object is used in a single-threaded way, with at most a single reference to it. If a value has a unique type, a function applied to it can be optimized to update the value in-place in the object code. Such in-place updates improve the efficiency of functional languages while maintaining referential transparency. Unique types can also be used to integrate functional and imperative programming. IntroductionUniqueness typing is best explained using an example. Consider a function function readLine(File f) returns String return line where String line = doImperativeReadLineSystemCall(f) end end Now However, using uniqueness typing, we can construct a new version of function readLine2(unique File f) returns (unique File, String) return (differentF, line) where String line = doImperativeReadLineSystemCall(f) File differentF = newFileFromExistingFile(f) end end The Programming languagesUniqueness types are implemented in the functional programming languages Clean, Mercury and Idris. They are sometimes used for doing I/O operations in functional languages in lieu of monads. A compiler extension has been developed for the Scala programming language which uses annotations to handle uniqueness in the context of message passing between actors.[1] Relationship to linear typingA unique type is very similar to a linear type, to the point that the terms are often used interchangeably, but there is in fact a distinction: actual linear typing allows a non-linear value to be typecast to a linear form, while still retaining multiple references to it. Uniqueness guarantees that a value has no other references to it, while linearity guarantees that no more references can be made to a value.[2] See also
References1. ^{{citation|last1=Haller|first1=P.|last2=Odersky|first2=M.|authorlink2=Martin Odersky|year=2010|contribution=Capabilities for uniqueness and borrowing|title=ECOOP 2010—Object-Oriented Programming|pages=354–378|url=http://lampwww.epfl.ch/~phaller/doc/capabilities-uniqueness2.pdf}} 2. ^{{cite conference |first=Philip |last=Wadler |authorlink=Philip Wadler |title=Is there a use for linear logic? |conference=ACM SIGPLAN symposium on partial evaluation and semantics-based program manipulation (PEPM '91) |date=17–19 June 1991 |url=http://homepages.inf.ed.ac.uk/wadler/topics/linear-logic.html#linearuse |pages=255–273 |doi=10.1145/115865.115894 |isbn=0-89791-433-3 |citeseerx=10.1.1.26.4202}} External links{{External links|date=February 2013}}
Discussions of uniqueness typing in programming languages
Experiments with uniqueness typing (from a performance perspective)
1 : Type theory |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。