<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 19, 2016, at 12:54 PM, David Waite &lt;<a href="mailto:david@alkaline-solutions.com" class="">david@alkaline-solutions.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 19, 2016, at 1:21 PM, Douglas Gregor &lt;<a href="mailto:dgregor@apple.com" class="">dgregor@apple.com</a>&gt; wrote:</div><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><br class=""></div><div class="">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</div></div></div></blockquote><div class=""><br class=""></div>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&lt;SequenceType where .Element == Element&gt; where needed.</div></div></div></blockquote><div><br class=""></div><div>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.</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>- Doug</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>typealias AnyCollection&lt;Element&gt; = protocol&lt;CollectionType where .Element == Element&gt;</div></div></div></blockquote><div class=""><br class=""></div>Eventually if you had typealiases in protocols (since the keyword will be freed up eventually due to the new associatedtype keyword) you could declare</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class=""><div class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);">protocol<span class="">&nbsp;SequenceType {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);"><span class="">&nbsp; associatedtype Element</span></div></div></div></div></div></div></div></div></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">&nbsp; typealias</span>&nbsp;SubSequence = protocol&lt;SequenceType where .Element = Self.Element&gt;</div></div></div></div></div></div></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">But thats a whole bucket of deprecation issues which aren’t worth it ATM - it would be a proposal for Swift 4.</div><div class=""><br class=""></div><div class="">-DW</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><br class=""></div><div class="">to cover the common case.</div><div class=""><br class=""></div><span class="Apple-tab-span" style="white-space: pre;">        </span>- Doug</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class=""><br class=""></div><div class="">Example of a simple protocol which models a node of a tree:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">// Before</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">// NodeType can be anything</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">// currently Swift doesn't allow</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">// `typealias NodeType: Node`</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">//</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">// or even where clauses&nbsp;</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">// `typealias NodeType: Node where NodeType.T == T`</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);">protocol<span class="">&nbsp;Node {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);"><span class=""><span class="Apple-tab-span" style="white-space: pre;">        </span></span>typealias<span class="">&nbsp;T</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(187, 44, 162);">typealias</span>&nbsp;NodeType</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><span class="Apple-tab-span" style="white-space: pre;">        </span><br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(187, 44, 162);">var</span>&nbsp;value:&nbsp;<span class="" style="color: rgb(112, 61, 170);">T</span>&nbsp;{&nbsp;<span class="" style="color: rgb(187, 44, 162);">get</span>&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(187, 44, 162);">var</span>&nbsp;nodes: [<span class="" style="color: rgb(112, 61, 170);">NodeType</span>] {&nbsp;<span class="" style="color: rgb(187, 44, 162);">get</span>&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">// After</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">protocol</span>&nbsp;Node&lt;T&gt; {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);"><span class=""><span class="Apple-tab-span" style="white-space: pre;">        </span></span>typealias<span class="">&nbsp;T&nbsp;</span><span class="" style="color: rgb(0, 132, 0);">// probably remove this declaration (see reason below)</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(187, 44, 162);">var</span>&nbsp;value:&nbsp;<span class="" style="color: rgb(112, 61, 170);">T</span>&nbsp;{&nbsp;<span class="" style="color: rgb(187, 44, 162);">get</span>&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(187, 44, 162);">var</span>&nbsp;nodes: [<span class="" style="color: rgb(112, 61, 170);">Node</span>&lt;T&gt;] {&nbsp;<span class="" style="color: rgb(187, 44, 162);">get</span>&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><br class=""></div><div class=""><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><div class="">So a generic parameter is placed after the protocol name. Therefore a corresponding associated type could be synthesized making its declaration in the body of the protocol unnecessary.</div><div class=""><br class=""></div><div class="">In order to let this still compile:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">func</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;afunction&lt;S:&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);">where</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">S</span><span class="" style="font-family: Menlo; font-size: 11px;">.</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Generator</span><span class="" style="font-family: Menlo; font-size: 11px;">.</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Element</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;==&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Int</span><span class="" style="font-family: Menlo; font-size: 11px;">&gt;(s:&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">S</span><span class="" style="font-family: Menlo; font-size: 11px;">){}</span></div><div class=""><span class="" style="font-family: Menlo; font-size: 11px;"><br class=""></span></div><div class="">there could be a general Swift feature to get the generic type by dot syntax (e.g. synthesized typealiases for every generic parameter).</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Implementation:</div><div class="">The function declaration above could be rewritten to using a function like generic parameter parameter syntax for protocols:</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;">// Declaration of SequenceType</span></div><div class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">protocol&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">&lt;<font color="#703daa" class="">Element</font>:<font color="#703daa" class=""><span class="Apple-converted-space">&nbsp;</span>Generator.Element</font>,</span>&nbsp;<span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Generator</span><span class="" style="font-family: Menlo; font-size: 11px;">:</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;"><span class="Apple-converted-space">&nbsp;</span>GeneratorType</span><span class="" style="font-family: Menlo; font-size: 11px;">,</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SubSequence</span><font face="Menlo" class=""><span class="" style="font-size: 11px;">&gt; {&nbsp;…&nbsp;}</span></font></div><div class=""><font face="Menlo" class=""><span class="" style="font-size: 11px;">&nbsp; &nbsp;&nbsp;</span></font><span class="" style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^~~~ using : in oder to allow default types with =</span></div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;">// Using "_" to leave it unspecified eg. Any</span></div><div class=""><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">&nbsp; &nbsp; func</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;afunction(s:&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType&lt;Element: Int</span><span class="" style="font-family: Menlo; font-size: 11px;">,</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;"><span class="Apple-converted-space">&nbsp;</span>Generator: GeneratorType</span><span class="" style="font-family: Menlo; font-size: 11px;">&lt;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Element</span><span class="" style="font-family: Menlo; font-size: 11px;">:</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;"><span class="Apple-converted-space">&nbsp;</span>Int</span><span class="" style="font-family: Menlo; font-size: 11px;">&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">,</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;"><span class="Apple-converted-space">&nbsp;</span>SubSequence: _&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">){}</span></div><div class=""><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;">// omitting `SubSequence: _` since the type is already unambiguous</span></div><div class=""><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">&nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">func</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;afunction(s:&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">&lt;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Element</span><span class="" style="font-family: Menlo; font-size: 11px;">:</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">&nbsp;Int</span><span class="" style="font-family: Menlo; font-size: 11px;">,</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;"><span class="Apple-converted-space">&nbsp;</span>Generator:&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px;"><span class="" style="color: rgb(112, 61, 170);">GeneratorType</span><span class="">&lt;</span><span class="" style="color: rgb(112, 61, 170);">Element</span><span class="">:</span><span class="" style="color: rgb(112, 61, 170);">&nbsp;Int</span><span class="">&gt;</span>&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">){}</span></div><div class=""><span class="" style="font-family: Menlo; font-size: 11px;"><div class="" style="font-family: Helvetica; font-size: 12px;"><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;">// omitting `Generator: GeneratorType&lt;Int&gt;` since the type of `Generator` can be inferred from Element</span></div><div class="" style="font-family: Helvetica; font-size: 12px;"><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">&nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">func</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;afunction(s:&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">&lt;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Element</span><span class="" style="font-family: Menlo; font-size: 11px;">:</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">&nbsp;Int</span><span class="" style="font-family: Menlo; font-size: 11px;">&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">){}</span></div></span></div><div class=""><span class="" style="font-family: Menlo; font-size: 11px;"><br class=""></span></div><div class="">The order of arguments is in this case irrelevant, but should probably be in a strict ordering to make it more consistent with the point below.</div><div class=""><br class=""></div><div class="">In order to have a more general generic parameter behavior (to work with structs, classes and enums) we could also allow to use these without external names and only their order. So the example above would look like this:</div><div class=""><br class=""></div><div class=""><div class=""><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">&nbsp; &nbsp; func</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;afunction(s:&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType&lt;Int</span><span class="" style="font-family: Menlo; font-size: 11px;">,</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">&nbsp;GeneratorType&lt;Int&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">,&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">_&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">){}</span></div><div class=""><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">&nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">func</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;afunction(s:&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">&lt;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Int</span><span class="" style="font-family: Menlo; font-size: 11px;">,&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">GeneratorType&lt;Int&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">){}</span></div><div class=""><span class="" style="font-family: Menlo; font-size: 11px;"><div class="" style="font-family: Helvetica; font-size: 12px;"><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">&nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">func</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;afunction(s:&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">&lt;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Int</span><span class="" style="font-family: Menlo; font-size: 11px;">&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">){}</span></div><div class="" style="font-family: Helvetica; font-size: 12px;"><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp; &nbsp;&nbsp;</span></div><div class="" style="font-family: Helvetica; font-size: 12px;"><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;">// These two functions don't produce an error since `Element` can be inferred</span></div><div class="" style="font-family: Helvetica; font-size: 12px;"><span class="" style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;">&nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">func</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;afunction(s:&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType&lt;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">GeneratorType&lt;Int&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">,&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">_&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">){}</span></div></span><div class=""><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">&nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(187, 44, 162); font-family: Menlo; font-size: 11px;">func</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;afunction(s:&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">&lt;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">GeneratorType&lt;Int&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">){}</span></div><div class=""><span class="" style="font-family: Menlo; font-size: 11px;"><br class=""></span></div><div class=""><span class="" style="font-family: Menlo; font-size: 11px;"><span class="" style="color: rgb(0, 132, 0);">&nbsp; &nbsp; // for an unconstrained Sequence "_" can be used in order to make it clear: "there could be generic parameters"</span></span></div><div class=""><span class="" style="font-family: Menlo; font-size: 11px;"><span class="" style="color: rgb(187, 44, 162);">&nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="">&nbsp;afunction(s:&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">SequenceType</span><span class="">&lt;_</span><span class="">&gt;</span><span class="">){}</span></span></div></div></div><div class=""><br class=""></div><div class="">For instance `Array` and `Dictionary` also can apply to this model.</div><div class=""><br class=""></div><div class="">Also where clauses could be used in generic parameter declarations which are disallowed for associated types (currently).</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">What do you think about this approach?</div><div class=""><br class=""></div><div class="">Should&nbsp;<span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">&lt;_</span><span class="" style="font-family: Menlo; font-size: 11px;">&gt;&nbsp;</span>be<span class="Apple-converted-space">&nbsp;</span><b class="">equal</b><span class="Apple-converted-space">&nbsp;</span>to&nbsp;<span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">&lt;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Any</span><span class="" style="font-family: Menlo; font-size: 11px;">&gt; /&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">&lt;<span class="" style="color: rgb(112, 61, 170);">Element</span>:&nbsp;</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Any</span><span class="" style="font-family: Menlo; font-size: 11px;">&gt;</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;</span>?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">- Maximilian</div></div></div></div></div></div></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">Am 19.01.2016 um 00:32 schrieb David Waite via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 18, 2016, at 1:18 PM, Douglas Gregor &lt;<a href="mailto:dgregor@apple.com" class="">dgregor@apple.com</a>&gt; wrote:</div><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class="">let x:SequenceType = [1,2,3] // no constraints specified whatsoever</div><div class="">let y:protocol&lt;SequenceType where Generator.Element == String&gt; = [“foo”, “bar”] // partially constrained</div></blockquote></div></blockquote><div class=""><br class=""></div>Not wanting to start throwing paint, but "Generator.Element" could be ambiguous with a Generator in the lexical scope. You'll probably want some way to differentiate it (eg, a leading dot). Otherwise, this is the syntactic direction that I think makes the most sense.</div></div></div></blockquote><div class=""><br class=""></div>Yes, I’ll use that below. There is a right balance in extending protocol&lt;&gt;. For instance, I did not like the following at all:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>protocol&lt;S:SequenceType where S.Generator.Element == String&gt;</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="">One interesting side-effect to note is that SequenceType could be redefined to only have “Element” as an associated type. Instead of Generator or SubSequence being associated types, methods could return partially constrained GenericType or SequenceType from the appropriate methods. This would be one way of eliminating issues today with recursive use of associated types (as well as SubSequence over-constraining the output of various algorithms to a single concrete type)</div></div></blockquote><div class=""><br class=""></div><div class="">Assuming nobody cares about the identity of the Generator type, which is probably a safe assumption. Note that one could implement this design today by using a function taking no arguments and returning an Element? in lieu of "Generator”.</div></div></div></div></blockquote><div class=""><br class=""></div>Yes, as an aside I was actually curious GeneratorType existed when I was first diving into the standard library, considering it could just be a closure.</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""></div><div class="">For the “opening” of an existential type to find the concrete type it stores dynamically, I’m currently using a different syntax just because the “open x as T” originally given makes ‘open’ a keyword’ and makes it unclear where ’T’ came from</div></div></blockquote><div class=""><br class=""></div><div class="">Yes, the issue of "which name did I introduce?" is tricky here.&nbsp;</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">- I’m instead overloading the typealias keyword when used within an expression context:</div><div class=""><br class=""></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class="">typealias T = x.dynamicType</div><div class="">let xT = x as! T</div></blockquote></div></blockquote><div class=""><br class=""></div>x will have to be immutable for this to make sense. That's why my ugly "open" expression extracts a new value and gives it a fresh type in one lexically-scoped block. Both the type and the value end up being scoped. Otherwise, one might reassign "x" with a different dynamic type... Then what does T mean?</div></div></div></blockquote><div class=""><br class=""></div><div class="">This is an area that I need to understand compiler behavior more here (I’ve been researching)</div><div class=""><br class=""></div><div class="">If ’T’ internally behaves like an immutable variable with lexical scope, then ’typealias’ in a code block is just another statement, and the type would be based on the value of ‘x’ at the point of execution:</div><div class=""><br class=""></div></div><div class="">var x:Any = “Initial”</div><div class="">typealias T = x.dynamicType // String</div><div class="">x = 1</div><div class="">let xT = x as! T // fails precondition as if I had said x as! String</div><div class=""><br class=""></div><div class="">I’m guessing from your comment however that T would not a variable. In which case, it makes sense to be more restrictive in use (such as requiring immutability). This is also more consistent with the use of typealias in other contexts, if that was the syntax one was going with.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I suggest you also look at what can be done with an existential value that hasn't been opened explicitly. Can I call "generate" on a SequenceType value, and what do I get back?</div></div></blockquote><div class=""><br class=""></div>Depends on how far we are willing to go. If you are only willing to expose the invariants in the face of the constraints given (in this case none), all you would get exposed is “underestimateCount”.</div><div class=""><br class=""></div><div class="">If you are willing to expose anything which can be expressed by certain type safety rules (needing formal definition later), then you can do quite a bit.</div><div class=""><br class=""></div><div class="">To start, let me express SequenceType relying on the partially constrained protocols, taking a few liberties:&nbsp;</div><div class="">- pruning some alternate forms</div><div class="">- removing SubSequence and Generator associated types and just having Element</div><div class="">- using the protocol&lt;&gt; syntax described before (with . prefix)</div><div class="">- returning partially constrained SequenceTypes rather than stdlib concrete types like JoinSequence in a few cases.&nbsp;</div><div class="">- eliminate usage of AnySequence in definitions (not needed)</div><div class="">- assuming a change in protocol LazySequenceType to be expressed in terms of Element rather than a base SequenceType</div><div class=""><br class=""></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">protocol</span><span class="Apple-converted-space">&nbsp;</span>SequenceType {</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; associatedtype Element</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">var</span><span class="Apple-converted-space">&nbsp;</span>lazy:<span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(112, 61, 170);">LazySequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element&gt; {<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">get</span><span class="Apple-converted-space">&nbsp;</span>}</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>contains(<span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>predicate:(Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span><span class="Apple-converted-space">&nbsp;</span>-&gt; Bool)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span><span class="Apple-converted-space">&nbsp;</span>-&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Bool</span></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>dropFirst(n:<span class="" style="color: rgb(112, 61, 170);">Int</span>) -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element&gt;</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>dropLast(n:<span class="" style="color: rgb(112, 61, 170);">Int</span>) -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element&gt;</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>elementsEqual(other:<span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span>&nbsp;<span class="" style="color: rgb(187, 44, 162);">where</span>&nbsp;.Element == Element&gt;,<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>isEquivalent: (Element, Element)) -&gt; Bool</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>enumerate() -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == (Int, Element)&gt;</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>filter(<span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>includeElement: (Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span>-&gt; Bool)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span><span class="Apple-converted-space">&nbsp;</span>-&gt; [<span class="" style="color: rgb(112, 61, 170);">Element</span>]</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>flatMap&lt;E&gt;(transform: (Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span><span class="Apple-converted-space">&nbsp;</span>-&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;SequenceType<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element:E&gt;)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span><span class="Apple-converted-space">&nbsp;</span>-&gt; [<span class="" style="color: rgb(79, 129, 135);">E</span>]</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>flatMap&lt;T&gt;(<span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>transform: (Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span><span class="Apple-converted-space">&nbsp;</span>-&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(79, 129, 135);">T</span>?)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span><span class="Apple-converted-space">&nbsp;</span>-&gt; [<span class="" style="color: rgb(79, 129, 135);">T</span>]</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>forEach(<span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>body: (Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span><span class="Apple-converted-space">&nbsp;</span>-&gt; ())<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>generate() -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(112, 61, 170);">GeneratorType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element&gt;</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>lexicographicalCompare(other:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element&gt;,<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>isOrderedBefore:(Element,Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span>-&gt; Bool)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span><span class="Apple-converted-space">&nbsp;</span>-&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Bool</span></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>map&lt;T&gt;(<span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>transform: (Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span><span class="Apple-converted-space">&nbsp;</span>-&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(79, 129, 135);">T</span>)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span><span class="Apple-converted-space">&nbsp;</span>-&gt; [<span class="" style="color: rgb(79, 129, 135);">T</span>]</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>maxElement(<span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>isOrderedBefore: (Element,Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span><span class="Apple-converted-space">&nbsp;</span>-&gt; Bool)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span><span class="Apple-converted-space">&nbsp;</span>-&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Element</span>?</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>minElement(<span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>isOrderedBefore: (Element,Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span><span class="Apple-converted-space">&nbsp;</span>-&gt; Bool)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span><span class="Apple-converted-space">&nbsp;</span>-&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Element</span>?</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>prefix(n:<span class="" style="color: rgb(112, 61, 170);">Int</span>) -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element&gt;</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>reduce&lt;T&gt;(initial:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(79, 129, 135);">T</span>,<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>combine: (<span class="" style="color: rgb(79, 129, 135);">T</span>, Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span><span class="Apple-converted-space">&nbsp;</span>-&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(79, 129, 135);">T</span>)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span><span class="Apple-converted-space">&nbsp;</span>-&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(79, 129, 135);">T</span></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>reverse() -&gt; [<span class="" style="color: rgb(112, 61, 170);">Element</span>]</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>sort(<span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>isOrderedBefore: (Element,Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span><span class="Apple-converted-space">&nbsp;</span>-&gt; Bool)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span><span class="Apple-converted-space">&nbsp;</span>-&gt; [<span class="" style="color: rgb(112, 61, 170);">Element</span>]</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>split(maxSplit:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Int</span>, allowEmptySubsequences:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Bool</span>,<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>isSeparator: (Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span><span class="Apple-converted-space">&nbsp;</span>-&gt; Bool)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span><span class="Apple-converted-space">&nbsp;</span>-&gt; [<span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element&gt;]</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>startsWith(other:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element&gt;,<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">@noescape</span><span class="Apple-converted-space">&nbsp;</span>isEquivalent: (Element, Element)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">throws</span><span class="Apple-converted-space">&nbsp;</span>-&gt; Bool)<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">rethrows</span><span class="Apple-converted-space">&nbsp;</span>-&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Bool</span></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>suffix(n:<span class="" style="color: rgb(112, 61, 170);">Int</span>) -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element&gt;</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>underestimateCount() -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Int</span></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">extension</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>Element:Equatable {</div></div><div class=""><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">func</span>&nbsp;elementsEqual&lt;OtherSequence :&nbsp;<span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span>&nbsp;<span class="" style="color: rgb(187, 44, 162);">where</span>&nbsp;.Element == Element&gt;(other: OtherSequence) -&gt; Bool</div></div><div class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>split(separator:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Element</span>, maxSplit:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Int</span>, allowEmptySlices:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Bool</span>) -&gt; [<span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(112, 61, 170);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element&gt;]</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>startsWith(other:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(112, 61, 170);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element) -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Bool</span></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">extension</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>Element == String {</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>joinWithSeparator(separator:<span class="" style="color: rgb(112, 61, 170);">String</span>) -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">String</span></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">extension</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>Element:<span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;SequenceType&gt;</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>flatten() -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element.Element&gt;</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>joinWithSeparator(separator:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element = Element.Element&gt;) -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element.Element&gt;)</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">extension</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(79, 129, 135);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>Element:Comparable {</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>lexicographicalCompare(other:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">protocol</span>&lt;<span class="" style="color: rgb(112, 61, 170);">SequenceType</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">where</span><span class="Apple-converted-space">&nbsp;</span>.Element == Element&gt;) -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Bool</span></div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>maxElement() -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Element</span>?</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>minElement() -&gt;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Element</span>?</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>sort() -&gt; [<span class="" style="color: rgb(112, 61, 170);">Element</span>]</div></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div></blockquote>Now, mapping this in terms of just an unconstrained SequenceType, which is shorthand for protocol&lt;SequenceType where .Element:Any&gt;:<div class="">- None of the extensions match the constraint on Element, so they are not exposed</div><div class="">- property Lazy is exposed as an unconstrained LazySequenceType, aka protocol&lt;LazySequenceType where .Element:Any&gt;</div><div class="">- the predicate function in contains is not constrained by a particular kind of element, so it becomes (Any)-&gt;Bool, e.g.:</div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);">func</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;contains(</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);">@noescape</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;predicate:(Any)&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);">throws</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;-&gt; Bool)&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);">rethrows</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;-&gt;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(112, 61, 170);">Bool</span></div></blockquote><div class=""><div class="">- dropFirst/dropLast would return an unconstrained SequenceType. This would need to leverage rules around constrained protocol variance/equivalence.</div><div class="">- elementsEqual was changed to no longer be generic - one can pass in any SequenceType constrained to have the same Element type. The function parameter, similar to contains above, now has the signature (Any, Any)-&gt;Bool</div><div class="">- enumerate() will return a sequence with elements of type (Int, Any)</div><div class="">- filter takes a (Any) throws -&gt; Bool method and returns [Any]</div><div class="">- flatMap and forEach are exposed similar to contains above</div><div class="">- generate returns an unconstrained GeneratorType (so it will have a single method func next() -&gt; Any?)</div><div class="">- lexicographicalCompare fails, more below</div><div class="">- reduce has effective syntax:</div></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><div class="">&nbsp;<span class="" style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);">func</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;reduce&lt;T&gt;(initial:&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);">T</span><span class="" style="font-family: Menlo; font-size: 11px;">,&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);">@noescape</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;combine: (</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);">T</span><span class="" style="font-family: Menlo; font-size: 11px;">, Any)&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);">throws</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;-&gt;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);">T</span><span class="" style="font-family: Menlo; font-size: 11px;">)&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);">rethrows</span><span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;-&gt;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);">T</span></div></div></blockquote><div class="">- the rest are exposed as above except for startsWith</div><div class=""><br class=""></div><div class="">So all functionality except<span class="" style="font-family: Menlo; font-size: 11px;">&nbsp;lexicographicalCompare and&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px;">startsWith&nbsp;</span>could at least in theory be exposed safely. These cannot be exposed cleanly because method expected an input sequence with the same element type, but the element type is not invariantly constrained. Self properties and method arguments are an equivalent problem, except that for a Self argument can only be invariantly constrained when you know the implementing concrete type - hence wanting a system to dynamically reason about said types.</div><div class=""><br class=""></div><div class="">This seems like a good amount of exposed functionality. Granted, it is not free to work at the level of protocols vs concrete types, and this does not attempt to simplify that. However, this proposal seems to bridge the gap between protocols without associated types and protocols with them. I also am happy with the amount of functionality that can be exposed safely as well as the consistency (A lexicographicalCompare function working on heterogenous sequences would have to be declared differently)</div><div class=""><br class=""></div><div class="">-DW</div><div class=""><br class=""></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""></div></blockquote><div class=""><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"></blockquote></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div></div></div></blockquote></div></div></div></blockquote></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>