[swift-evolution] [Review] SE-0065 A New Model for Collections and Indices

Thorsten Seitz tseitz42 at icloud.com
Mon Apr 18 01:14:39 CDT 2016


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 at 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.


More information about the swift-evolution mailing list