<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 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 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=""><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><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><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>protocol&lt;S:SequenceType where S.Generator.Element == String&gt;</div><div><br class=""></div><div><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=""><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><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><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=""><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><br class=""></div><div>This is an area that I need to understand compiler behavior more here (I’ve been researching)</div><div><br class=""></div><div>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><br class=""></div></div><div>var x:Any = “Initial”</div><div>typealias T = x.dynamicType // String</div><div>x = 1</div><div>let xT = x as! T // fails precondition as if I had said x as! String</div><div><br class=""></div><div>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><br class=""></div><div><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="">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><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><br class=""></div><div>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><br class=""></div><div>To start, let me express SequenceType relying on the partially constrained protocols, taking a few liberties:&nbsp;</div><div>- pruning some alternate forms</div><div>- removing SubSequence and Generator associated types and just having Element</div><div>- using the protocol&lt;&gt; syntax described before (with . prefix)</div><div>- returning partially constrained SequenceTypes rather than stdlib concrete types like JoinSequence in a few cases.&nbsp;</div><div>- eliminate usage of AnySequence in definitions (not needed)</div><div>- assuming a change in protocol LazySequenceType to be expressed in terms of Element rather than a base SequenceType</div><div><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span> SequenceType {</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; associatedtype Element</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> lazy:<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">LazySequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element&gt; { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">get</span> }</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> contains(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> predicate:(Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -&gt; Bool) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> dropFirst(n:<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element&gt;</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> dropLast(n:<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element&gt;</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(187, 44, 162);" class="">func</span> elementsEqual(other:<span style="color: rgb(187, 44, 162);" class="">protocol</span>&lt;<span style="color: rgb(79, 129, 135);" class="">SequenceType</span>&nbsp;<span style="color: rgb(187, 44, 162);" class="">where</span>&nbsp;.Element == Element&gt;, <span style="color: rgb(187, 44, 162);" class="">@noescape</span> isEquivalent: (Element, Element)) -&gt; Bool</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> enumerate() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == (Int, Element)&gt;</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> filter(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> includeElement: (Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span>-&gt; Bool) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -&gt; [<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>]</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> flatMap&lt;E&gt;(transform: (Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;SequenceType <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element:E&gt;) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -&gt; [<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">E</span>]</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> flatMap&lt;T&gt;(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> transform: (Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span>?) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -&gt; [<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span>]</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> forEach(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> body: (Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -&gt; ()) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> generate() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">GeneratorType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element&gt;</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> lexicographicalCompare(other: <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element&gt;, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> isOrderedBefore:(Element,Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span>-&gt; Bool) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> map&lt;T&gt;(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> transform: (Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span>) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -&gt; [<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span>]</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> maxElement(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> isOrderedBefore: (Element,Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -&gt; Bool) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>?</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> minElement(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> isOrderedBefore: (Element,Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -&gt; Bool) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>?</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> prefix(n:<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element&gt;</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> reduce&lt;T&gt;(initial: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> combine: (<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span>, Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span>) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> reverse() -&gt; [<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>]</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> sort(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> isOrderedBefore: (Element,Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -&gt; Bool) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -&gt; [<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>]</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> split(maxSplit: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>, allowEmptySubsequences: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> isSeparator: (Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -&gt; Bool) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -&gt; [<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element&gt;]</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> startsWith(other: <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element&gt;, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> isEquivalent: (Element, Element) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -&gt; Bool) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> suffix(n:<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element&gt;</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> underestimateCount() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> Element:Equatable {</div></div><div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(187, 44, 162);" class="">func</span>&nbsp;elementsEqual&lt;OtherSequence :&nbsp;<span style="color: rgb(187, 44, 162);" class="">protocol</span>&lt;<span style="color: rgb(79, 129, 135);" class="">SequenceType</span>&nbsp;<span style="color: rgb(187, 44, 162);" class="">where</span>&nbsp;.Element == Element&gt;(other: OtherSequence) -&gt; Bool</div></div><div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> split(separator: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>, maxSplit: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>, allowEmptySlices: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span>) -&gt; [<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element&gt;]</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> startsWith(other: <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> Element == String {</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> joinWithSeparator(separator:<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span>) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> Element:<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;SequenceType&gt;</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> flatten() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element.Element&gt;</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> joinWithSeparator(separator: <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element = Element.Element&gt;) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element.Element&gt;)</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> Element:Comparable {</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> lexicographicalCompare(other: <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">protocol</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">SequenceType</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> .Element == Element&gt;) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span></div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> maxElement() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>?</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> minElement() -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>?</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> sort() -&gt; [<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Element</span>]</div></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</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 style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">func</span><span style="font-family: Menlo; font-size: 11px;" class="">&nbsp;contains(</span><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">@noescape</span><span style="font-family: Menlo; font-size: 11px;" class="">&nbsp;predicate:(Any)&nbsp;</span><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">throws</span><span style="font-family: Menlo; font-size: 11px;" class="">&nbsp;-&gt; Bool)&nbsp;</span><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">rethrows</span><span style="font-family: Menlo; font-size: 11px;" class="">&nbsp;-&gt;&nbsp;</span><span style="font-family: Menlo; font-size: 11px; color: rgb(112, 61, 170);" class="">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 style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class="">&nbsp;<span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">func</span><span style="font-family: Menlo; font-size: 11px;" class="">&nbsp;reduce&lt;T&gt;(initial:&nbsp;</span><span style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);" class="">T</span><span style="font-family: Menlo; font-size: 11px;" class="">,&nbsp;</span><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">@noescape</span><span style="font-family: Menlo; font-size: 11px;" class="">&nbsp;combine: (</span><span style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);" class="">T</span><span style="font-family: Menlo; font-size: 11px;" class="">, Any)&nbsp;</span><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">throws</span><span style="font-family: Menlo; font-size: 11px;" class="">&nbsp;-&gt;&nbsp;</span><span style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);" class="">T</span><span style="font-family: Menlo; font-size: 11px;" class="">)&nbsp;</span><span style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);" class="">rethrows</span><span style="font-family: Menlo; font-size: 11px;" class="">&nbsp;-&gt;&nbsp;</span><span style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);" class="">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 style="font-family: Menlo; font-size: 11px;" class="">&nbsp;lexicographicalCompare and&nbsp;</span><span style="font-family: Menlo; font-size: 11px;" class="">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 style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div class=""></div></blockquote><div class=""><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""></blockquote></div></body></html>