3 ms·
> I really like the name "Linear Types" better than RAII. They're not the same thing. > C++ ctor/dtor pairs are a sort of primitive linear type system that fo
by masklinn 9y ago
> I really like the name "Linear Types" better than RAII.
They're not the same thing.
> C++ ctor/dtor pairs are a sort of primitive linear type system that forces exactly one (implicit) use for each instance created.
ctor/dtor are closer to what Rust provides which is an affine type system. Linear types must be used exactly once, affine types can be used at most once. You can initialise a C++ object and never use it, that would not be allowed in a linear type system.
- clord 9y agoI completely agree they're not the same things, but you can sort of see the "linear type" notion of "one and only one use" in RAII. Every construction has exactly one use (destruction.) it's fairly easy to see that RAII is a very limited version of a linear type system. In an affine type system, every variable is used at most once. But C++ instantiations for RAII are not destructed more than once. Each instantiation has exactly one destruction.
- masklinn 9y ago> Every construction has exactly one use (destruction.) it's fairly easy to see that RAII is a very limited version of a linear type system. Aside from actually having it integrated to the type system, Rust does exactly that. RAII is not linear. > But C++ instantiations for RAII are not destructed more than once. That's also what happens in Rust, it's not a linear type system.
- OJFord 9y ago> easy to see that RAII is a very limited version of a linear type system. You might be interested in [0]. Affine logic rejects only the contraction rule [1]; unlike linear systems still has weakening [2]. [0]: https://en.wikipedia.org/wiki/Substructural_type_system https://en.wikipedia.org/wiki/Substructural_type_system [1]: https://en.wikipedia.org/wiki/Idempotency_of_entailment https://en.wikipedia.org/wiki/Idempotency_of_entailment [2]: https://en.wikipedia.org/wiki/Monotonicity_of_entailment https://en.wikipedia.org/wiki/Monotonicity_of_entailment
- mcguire 9y agoI thought the "use" was the destruction or movement of the value, in which case an object is used exactly once. You may never use a C++ object, but it will be destroyed (under normal circumstances).
- masklinn 9y ago> I thought the "use" was the destruction or movement of the value Implicit behaviour is not use. > You may never use a C++ object, but it will be destroyed (under normal circumstances). And that is different from Rust how? https://gankro.github.io/blah/linear-rust/#must-be-used-at-least-once https://gankro.github.io/blah/linear-rust/#must-be-used-at-l...