[swift-evolution] Partially Constrained Protocols [Was: [Proposal] Separate protocols and interfaces]

Douglas Gregor dgregor at apple.com
Wed Jan 20 00:58:12 CST 2016


> On Jan 19, 2016, at 5:23 PM, David Waite <david at alkaline-solutions.com> wrote:
> 
>> 
>> On Jan 19, 2016, at 3:45 PM, Douglas Gregor <dgregor at apple.com> wrote:
>> 
>> 
>>> On Jan 19, 2016, at 12:54 PM, David Waite <david at alkaline-solutions.com> wrote:
>>> 
>>> 
>>>> On Jan 19, 2016, at 1:21 PM, Douglas Gregor <dgregor at apple.com> wrote:
>>>> 
>>>> Right. There’s also SubSequence, which you almost certainly don’t want to have to specify. For reference, once we get generic typealiases, one would be free to add
>>> 
>>> Yes, although in the version of SequenceType which declared earlier in the thread, there was no longer a need for SubSequence, as I could just return protocol<SequenceType where .Element == Element> where needed.
>> 
>> I suspect that there is a class of algorithms for which it is interesting to limit ourselves to “SubSequence == Self”, which one would lose by making SubSequence an existential.
>> 
>> 	- Doug
> 
> So something like the following?
> 
> 	protocol SequenceType {
> 	    associatedtype Element 
> 	    associatedtype SubSequence:protocol<SequenceType where .Element == Element>
>> 	}
> 	
> 	extension SequenceType where SubSequence == Self {
>> 	}


Yes, exactly. I found 6 occurrences of this in the Swift standard library.

	- Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160119/bc947c18/attachment.html>


More information about the swift-evolution mailing list