top | item 14249640

(no title)

musicnarcoman | 8 years ago

Hmm, I thought Rust uses something like affine types [0] (which is similar to linear types).

[0] https://www.reddit.com/r/rust/comments/4mdgux/rust_and_affin...

discuss

order

agumonkey|8 years ago

Right, that's the kind of subtleties I wanted to understand.

theseoafs|8 years ago

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.

So affine types give you a little more leeway.