In rust, mutable parameters are a separate type than immutable parameters. I wonder if this would be useful in languages even *without* a borrow checker.
ie I write the function
fn add_one(x: mut int)
The compiler would *prevent* passing an immutable integer in (which would be the default type)
ie I write the function
fn add_one(x: mut int)
The compiler would *prevent* passing an immutable integer in (which would be the default type)
Comments
You would want a mutable reference for your example, I think.
Then again, what if you're looking at an alias to a mutable var, how do you know it's updated
Wait fuck I just reinvented the borrow checker
https://bsky.app/profile/steveklabnik.com/post/3ldh7gbbles2w
Standard ML can do things like this with passing values vs ref cells containing values, if I remember right.
if you pass &i32 you can only "see" the value behind the reference but not change it (this makes more sense with structs j think)