Avatar
↓ path-dependent type なるものが必要らしい。 func nthOfEach( _ n: Int, from heterogeneousCollections: [any Collection] ) -> Any { return heterogeneousCollections.map { collection in // collection is `any Collection` let nthIndex = collection.startIndex.advanced(by: n) // error: inferred static type of nthIndex is something like `any Collection.Index`, // so compiler can’t guarantee it indexes `collection` … correct? return collection[nthIndex] } } https://forums.swift.org/t/se-0244-opaque-result-types-reopened/22942/49
These examples require “path-dependent types” to work. There are some examples in the old enhanced existentials draft (although it does not use the term path-dependent types). Also, fwiw Scala’s type system supports this feature. I don’t know Scala in depth so I’...