`Borrow` and `Inout` types for safe, first-class references

While this is true, you will very quickly realize you run into ambiguity issues if you didn’t have the accessors:

struct Array<Element: ~Copyable>: ~Copyable {
  subscript(i: Int) -> Borrow<Element> {
    get { ... }
  }

  subscript(I: Int) -> Inout<Element> {
    mutating get { ... }
  }
}

let a = Array<Atomic<Int>>(...)
let b = a[0] // error: ambiguous use of subscript what type is 'B'?

Of course some languages have this problem solved, but our language’s type checker does not work like that. The borrow/mutate accessors help alleviate this issue.

1 Like