Linear types = "you must use this value exactly one time"
Affine (uniqueness) types = "you can use this value either zero or one times, but you can't use it more than once"
As an example, compare two languages: one with linear types and one with affine types. Let's say that you had a "File" type, a function "open()" that creates a file (either linear or affine as appropriate), and a function "close()" that consumes the file. Then this code would be legal in both languages with linear types and languages with affine types:
let f: File = open()
close(f)
Note that "f" is used once and only once, at which point the value is consumed. In a language with affine types, this is also kosher:
let f: File = open()
// Do nothing
This fails to compile in the language with linear types because "f" is never used. Finally, this code is never legal in either language:
let f: File = open()
close(f)
close(f)
... because "f" is used twice here, and neither linear types nor affine types allow that.
agumonkey|8 years ago
theseoafs|8 years ago
As an example, compare two languages: one with linear types and one with affine types. Let's say that you had a "File" type, a function "open()" that creates a file (either linear or affine as appropriate), and a function "close()" that consumes the file. Then this code would be legal in both languages with linear types and languages with affine types:
Note that "f" is used once and only once, at which point the value is consumed. In a language with affine types, this is also kosher: This fails to compile in the language with linear types because "f" is never used. Finally, this code is never legal in either language: ... because "f" is used twice here, and neither linear types nor affine types allow that.So affine types give you a little more leeway.