(no title)
waltpad | 5 years ago
Elaborating on this, with a function signature like the following:
fn mult(x : Vec<f32>, y : Vec<f32>) -> Vec<f32> {
// matrix product implementation
}
arguments x and y cannot point to the same value, because a value cannot be moved twice.
A call like mult(a,a)
will generate an error.Conversely, with the following signature:
fn mult(x : &Vec<f32>, y : &Vec<f32>) -> Vec<f32> {
// ...
}
the call: mult(&a,&a)
will typecheck, because values are passed by reference.Now, nothing prevents one to implement the function square, based on the second version of mult:
fn square(x : Vec<f32>) -> Vec<f32> {
return mult(&x,&x)
}
which is type-linear on its parameter x, but computationally is not linear.Clearly your original question was spot on.
goldenkey|5 years ago