2 ms·
I don't find this answer satisfactory, because you also need to specify in Rust whether or not a function moves its argument(s). // This moves the argument
by paavohtl 6y ago
I don't find this answer satisfactory, because you also need to specify in Rust whether or not a function moves its argument(s).
// This moves the argument
fn func(a: A) -> B { .. }
func(x); // x is not accessible after this line
// This borrows the argument, and therefore won't move it
fn func(a: &A) -> B { .. }
func(&x); // x remains accessible after this line
- Ericson2314 6y agoFrom the perspective of Rust, Linear Haskell is going to seem quite weird, and I say that as Haskeller wishing that language extension was more like Rust. I'm not really sure how to explain it, but basically only functions that are themselves linear can have linear parameters, It's vaguely like "`Fn(A) -> B` only if `A: Copy`", and `FnOnce(A) -> B` only if `A: !Copy`, except there is no `Copy` or `!Copy` and the only say to determine it is `Fn` vs `FnOnce`.