<div>Thanks.</div><div><br></div>I found this proposal in pull requests after the email sent. <span></span><br><br>Anders Ha <<a href="mailto:hello@andersio.co">hello@andersio.co</a>> 於 2016年7月29日星期五 寫道:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>It is one of the items in the Generics Manifesto, and we had a discussion thread with a proposal on this already, however halted for being an addictive feature. Anyway, aren't discussions on post Swift 3 matters preferred to start on Aug 1?</div><div><br></div><div><br></div><div><br></div><div>Hart's proposal</div><div><a href="https://github.com/hartbit/swift-evolution/blob/master/proposals/XXXX-powerful-constraints-associated-types.md" target="_blank">https://github.com/hartbit/swift-evolution/blob/master/proposals/XXXX-powerful-constraints-associated-types.md</a></div><div><br></div><span>[swift-evolution] [Proposal] More Powerful Constraints for Associated Types<br></span><span></span><span><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160502/016354.html" target="_blank">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160502/016354.html</a></span><div><div><br></div><div><br></div><div><br></div><div>Regards,</div><div>Anders</div><div><br></div><br><div><blockquote type="cite"><div>On 29 Jul 2016, at 10:17 AM, Susan Cheng via swift-evolution <<a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div dir="ltr"><div>Hello swift c<span style="white-space:pre-wrap">ommunity,</span></div><div><span style="white-space:pre-wrap"><br></span></div><div><font><span style="white-space:pre-wrap">I want to i</span></font>ntroduce a proposal to allow constraints on associatedtype. </div><div>I found a bug report(<a href="https://bugs.swift.org/browse/SR-1466" target="_blank">https://bugs.swift.org/browse/SR-1466</a>) and it's due to without constraints on associatedtype itself.</div><div><br></div><div>This force us always have to write the redundant constraints like <span style="font-family:menlo;font-size:11px">Indices.Iterator.Element == Index</span> or <span style="font-family:menlo;font-size:11px">Indices.SubSequence.Iterator.Element == Index</span> on type constraints in function:<div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">extension</span><span> </span><span style="color:rgb(112,61,170)">MutableCollection</span><span> </span><span style="color:rgb(187,44,162)">where</span><span> </span><span style="color:rgb(187,44,162)">Self</span><span> : RandomAccessCollection, Indices.Index == Index, Indices.SubSequence : RandomAccessCollection, Indices.SubSequence.Iterator.Element == Index {</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span> </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> </span><span>/// Shuffle `self` in-place.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">mutating</span><span> </span><span style="color:rgb(187,44,162)">func</span><span> shuffle() {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">for</span><span> i </span><span style="color:rgb(187,44,162)">in</span><span> </span><span style="color:rgb(187,44,162)">self</span><span>.</span><span style="color:rgb(112,61,170)">indices</span><span>.</span><span style="color:rgb(61,29,129)">dropLast</span><span>() {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">let</span><span> j = </span><span style="color:rgb(187,44,162)">self</span><span>.</span><span style="color:rgb(112,61,170)">indices</span><span>.</span><span style="color:rgb(61,29,129)">suffix</span><span>(from: i).</span><span style="color:rgb(49,89,93)">random</span><span>()!</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">if</span><span> i != j {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(61,29,129)">swap</span><span>(&</span><span style="color:rgb(187,44,162)">self</span><span>[i], &</span><span style="color:rgb(187,44,162)">self</span><span>[j])</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>}</span></div></div><div><br></div><div>Besides this, we also can write some odd definitions but allowed by swift compiler.</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">struct</span><span> MyArray : </span><span style="color:rgb(112,61,170)">Collection</span><span> {</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span> </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)"><span> </span><span style="color:rgb(187,44,162)">typealias</span><span> Indices = </span><span>CountableRange</span><span><</span><span>Int32</span><span>></span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span> </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">var</span><span> base: [</span><span style="color:rgb(112,61,170)">Int</span><span>]</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span> </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">var</span><span> startIndex: </span><span style="color:rgb(112,61,170)">Int</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">return</span><span> </span><span style="color:rgb(79,129,135)">base</span><span>.</span><span style="color:rgb(112,61,170)">startIndex</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">var</span><span> endIndex: </span><span style="color:rgb(112,61,170)">Int</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">return</span><span> </span><span style="color:rgb(79,129,135)">base</span><span>.</span><span style="color:rgb(112,61,170)">endIndex</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">func</span><span> index(after: </span><span style="color:rgb(112,61,170)">Int</span><span>) -> </span><span style="color:rgb(112,61,170)">Int</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">return</span><span> after + </span><span style="color:rgb(39,42,216)">1</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> }</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span> </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)"><span> </span><span style="color:rgb(187,44,162)">var</span><span> indices: </span><span>CountableRange</span><span><</span><span>Int32</span><span>> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">return</span><span> </span><span style="color:rgb(112,61,170)">CountableRange</span><span>(uncheckedBounds: (lower: </span><span style="color:rgb(112,61,170)">Int32</span><span>(</span><span style="color:rgb(79,129,135)">startIndex</span><span>), upper: </span><span style="color:rgb(112,61,170)">Int32</span><span>(</span><span style="color:rgb(79,129,135)">endIndex</span><span>)))</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> }</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span> </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">subscript</span><span>(position: </span><span style="color:rgb(112,61,170)">Int</span><span>) -> </span><span style="color:rgb(112,61,170)">Int</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">get</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">return</span><span> </span><span style="color:rgb(79,129,135)">base</span><span>[position]</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">set</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(79,129,135)">base</span><span>[position] = newValue</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span><span style="font-family:arial,sans-serif;font-size:small">as a reference: </span></span><span style="font-family:arial,sans-serif;font-size:small"><a href="http://stackoverflow.com/questions/37581234/can-an-associated-type-be-restricted-by-protocol-conformance-and-a-where-clause" target="_blank">http://stackoverflow.com/questions/37581234/can-an-associated-type-be-restricted-by-protocol-conformance-and-a-where-clause</a></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-family:arial,sans-serif;font-size:small"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-family:arial,sans-serif;font-size:small">it's clearly that we need a syntax like this:</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">protocol</span><span> Collection : </span><span style="color:rgb(112,61,170)">Indexable</span><span>, </span><span style="color:rgb(112,61,170)">Sequence</span><span> {</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span> </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> </span><span>/// A sequence that represents a contiguous subrange of the collection's</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> </span><span>/// elements.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(0,132,0)">///</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> </span><span>/// This associated type appears as a requirement in the `Sequence`</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> </span><span>/// protocol, but it is restated here with stricter constraints. In a</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> </span><span>/// collection, the subsequence should also conform to `Collection`.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">associatedtype</span><span> SubSequence : IndexableBase, Sequence </span><span style="color:rgb(187,44,162)">where</span><span> SubSequence.Iterator.Element == Iterator.Element = Slice<</span><span style="color:rgb(187,44,162)">Self</span><span>></span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span> </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> </span><span>/// A type that can represent the indices that are valid for subscripting the</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> </span><span>/// collection, in ascending order.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span> </span><span style="color:rgb(187,44,162)">associatedtype</span><span> Indices : IndexableBase, Sequence </span><span style="color:rgb(187,44,162)">where</span><span> Indices.Iterator.Element == Index = DefaultIndices<</span><span style="color:rgb(187,44,162)">Self</span><span>></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">
</p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span><span style="font-family:arial,sans-serif;font-size:small"><br></span></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span><span style="font-family:arial,sans-serif;font-size:small">This </span><span style="font-family:arial,sans-serif;font-size:small">harmless and brings huge </span><span style="font-family:arial,sans-serif;font-size:small">benefits to swift.</span><br></span></div></div></div>
_______________________________________________<br>swift-evolution mailing list<br><a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></blockquote>