[Idea] Typealias for protocols with associated types

Currently protocols with associated types could not be used as types. One
could use type-erased wrappers (e.g. AnyGenerator,
AnyRandomAccessCollection etc.) but writing these produce a lot of
boilerplate code. I think it would be convenient to use something like this:

class MyClass {
    typealias IntCollection = CollectionType where
CollectionType.Generator.Element == Int

    var collection: IntCollection
}

I agree, as long as the typealias and second use of the type name is not necessary.

Because
extension CollectionType where Generator.Element == Int {}
compiles…

var collection: CollectionType where Generator.Element == Int
should also.

There is already a similar thread: [swift-evolution] Partially Constrained Protocols

There we discussed a more improved generics system including "true" generics for protocols with associated types:

var collection: CollectionType<Generator.Element == Int>

// if CollectionType had an Element typealias to Generator.Element

var collection: CollectionType<Element == Int>

Best regards
- Maximilian

···

Am 04.02.2016 um 19:01 schrieb Jessy Catterwaul via swift-evolution <swift-evolution@swift.org>:

I agree, as long as the typealias and second use of the type name is not necessary.

Because
extension CollectionType where Generator.Element == Int {}
compiles…

var collection: CollectionType where Generator.Element == Int
should also.
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution