Preventing indices of one collection being used by another collection can be 
done by using path dependent types like in Scala.

Then 'i' would have type a.Index (where 'a' is the instance!) and therefore 
b[i] would not typecheck as it would require an index of type b.Index

-Thorsten 

> Am 13.04.2016 um 03:39 schrieb Dmitri Gribenko via swift-evolution 
> <swift-evolution@swift.org>:
> 
> Ok, mutation can invalidate indices.  Can immutability help?
> 
> ---
> let a = [1, 2, 3]
> let b: [Int] = []
> let i = a.check(a.startIndex)
> b[i] // trap
> ---
> 
> Since it is not possible to encode the validity relationship in the
> type system, we want to encourage these operations to trap if they
> detect violations.
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to