Request for information about constrained protocol inheritance


(Jens Persson) #1

The following compiles in Swift 4 (but not in Swift 3.1):

protocol P1 {
    associatedtype A
}
protocol P2 : P1 where A == Int {
}

I've not been able to find any proposal, discussion or documentation
mentioning it so any pointers to such would be greatly appreciated.

Also, is this new feature used somewhere in the std lib?

/Jens


(Xiaodi Wu) #2

Replying to swift-users as well, as it's probably the more appropriate
forum.

SE-0142 (Permit where clauses to constrain associated types) is what
brought about this feature. It is now used in the standard library.

···

On Wed, Jul 5, 2017 at 00:26 Jens Persson via swift-evolution < swift-evolution@swift.org> wrote:

The following compiles in Swift 4 (but not in Swift 3.1):

protocol P1 {
    associatedtype A
}
protocol P2 : P1 where A == Int {
}

I've not been able to find any proposal, discussion or documentation
mentioning it so any pointers to such would be greatly appreciated.

Also, is this new feature used somewhere in the std lib?

/Jens
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Jens Persson) #3

Ah, thanks! Do you happen to know of any particular std lib protocol of the
form:
protocol P : OtherP where OtherP.AT ...
?

···

On Wed, Jul 5, 2017 at 7:53 AM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

Replying to swift-users as well, as it's probably the more appropriate
forum.

SE-0142 (Permit where clauses to constrain associated types) is what
brought about this feature. It is now used in the standard library.

On Wed, Jul 5, 2017 at 00:26 Jens Persson via swift-evolution < > swift-evolution@swift.org> wrote:

The following compiles in Swift 4 (but not in Swift 3.1):

protocol P1 {
    associatedtype A
}
protocol P2 : P1 where A == Int {
}

I've not been able to find any proposal, discussion or documentation
mentioning it so any pointers to such would be greatly appreciated.

Also, is this new feature used somewhere in the std lib?

/Jens
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Alex Martini) #4

Since you mentioned not finding documentation, here's the new section in "The Swift Programming Language":

Associated Types with a Generic Where Clause

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Generics.html#//apple_ref/doc/uid/TP40014097-CH26-ID557

···

On Jul 4, 2017, at 10:53 PM, Xiaodi Wu via swift-evolution <swift-evolution@swift.org> wrote:

Replying to swift-users as well, as it's probably the more appropriate forum.

SE-0142 (Permit where clauses to constrain associated types) is what brought about this feature. It is now used in the standard library.

On Wed, Jul 5, 2017 at 00:26 Jens Persson via swift-evolution <swift-evolution@swift.org> wrote:
The following compiles in Swift 4 (but not in Swift 3.1):

protocol P1 {
    associatedtype A
}
protocol P2 : P1 where A == Int {
}

I've not been able to find any proposal, discussion or documentation mentioning it so any pointers to such would be greatly appreciated.

Also, is this new feature used somewhere in the std lib?

/Jens
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution