Name: Anonymous 2014-12-02 10:58
While all the Rust-faggots and ATS-faggots are running around with their linear types dildo, the Imperative Lords have already solved the same problem much more simply. Their solution consists of just two simple ingredients: static single assignment (SSA) and const pointers. Check it out:
How do you mutate that array then? With SSA:
That's right, the binding to the mutated array just goes out of scope immediately after mutation, so there's no way to access it anymore. And in the call, you just provide a new binding for that same array (the compiler would issue a warning if you didn't) which goes into scope immediately after that same call. No new types needed! None of that type-theoretic bullshit and code duplication!
I wonder why no one ever thought of that.
int foo(int* arr);
...
int[] arr = {1, 2};
foo(arr);
print(arr[0]); // Compile-time error! But it would be OK if foo took a (const int* arr).
How do you mutate that array then? With SSA:
int foo(int* arr);
...
int[] arr = {1, 2};
foo(arr ~> arrMutated);
print(arrMutated[0]);
That's right, the binding to the mutated array just goes out of scope immediately after mutation, so there's no way to access it anymore. And in the call, you just provide a new binding for that same array (the compiler would issue a warning if you didn't) which goes into scope immediately after that same call. No new types needed! None of that type-theoretic bullshit and code duplication!
I wonder why no one ever thought of that.