I found the solution kind of weird. The solution I would have expected is quite simpler: arrays are mutable, but the type system always lets you go mutable -> const, but not const -> mutable. Of course, if you do let a = b where b is mutable, that doesn’t mean you can depend on a not changing, but that is the price you pay for using a language with mutability. It also means that var a = b where b is a const value means the compiler will forbid it, which lets you pay the cost of the copy if you want it, rather than being implicit.
I found the solution kind of weird. The solution I would have expected is quite simpler: arrays are mutable, but the type system always lets you go mutable -> const, but not const -> mutable. Of course, if you do
let a = bwherebis mutable, that doesn’t mean you can depend onanot changing, but that is the price you pay for using a language with mutability. It also means thatvar a = bwherebis a const value means the compiler will forbid it, which lets you pay the cost of the copy if you want it, rather than being implicit.Ahh….now I get it. I like the OPs suggestion more than mine.