<div dir="ltr"><div>Hello swift c<span style="color:rgb(0,0,0);white-space:pre-wrap">ommunity,</span></div><div><span style="color:rgb(0,0,0);white-space:pre-wrap"><br></span></div><div><font color="#000000"><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">https://bugs.swift.org/browse/SR-1466</a>) and it&#39;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:<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">public</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">extension</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(112,61,170)">MutableCollection</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">where</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">Self</span><span style="font-variant-ligatures: no-common-ligatures;"> : RandomAccessCollection, Indices.Index == Index, Indices.SubSequence : RandomAccessCollection, Indices.SubSequence.Iterator.Element == Index {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="font-variant-ligatures: no-common-ligatures;">/// Shuffle `self` in-place.</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    </span><span style="color:rgb(187,44,162)">mutating</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">func</span><span style="font-variant-ligatures: no-common-ligatures;"> shuffle() {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">        </span><span style="color:rgb(187,44,162)">for</span><span style="font-variant-ligatures: no-common-ligatures;"> i </span><span style="color:rgb(187,44,162)">in</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">self</span><span style="font-variant-ligatures: no-common-ligatures;">.</span><span style="color:rgb(112,61,170)">indices</span><span style="font-variant-ligatures: no-common-ligatures;">.</span><span style="color:rgb(61,29,129)">dropLast</span><span style="font-variant-ligatures: no-common-ligatures;">() {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">            </span><span style="color:rgb(187,44,162)">let</span><span style="font-variant-ligatures: no-common-ligatures;"> j = </span><span style="color:rgb(187,44,162)">self</span><span style="font-variant-ligatures: no-common-ligatures;">.</span><span style="color:rgb(112,61,170)">indices</span><span style="font-variant-ligatures: no-common-ligatures;">.</span><span style="color:rgb(61,29,129)">suffix</span><span style="font-variant-ligatures: no-common-ligatures;">(from: i).</span><span style="color:rgb(49,89,93)">random</span><span style="font-variant-ligatures: no-common-ligatures;">()!</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">            </span><span style="color:rgb(187,44,162)">if</span><span style="font-variant-ligatures: no-common-ligatures;"> i != j {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">                </span><span style="color:rgb(61,29,129)">swap</span><span style="font-variant-ligatures: no-common-ligatures;">(&amp;</span><span style="color:rgb(187,44,162)">self</span><span style="font-variant-ligatures: no-common-ligatures;">[i], &amp;</span><span style="color:rgb(187,44,162)">self</span><span style="font-variant-ligatures: no-common-ligatures;">[j])</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">            }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">        }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">}</span></p></div><div><br></div><div>Besides this, we also can write some odd definitions but allowed by swift compiler.</div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">struct</span><span style="font-variant-ligatures: no-common-ligatures;"> MyArray : </span><span style="color:rgb(112,61,170)">Collection</span><span style="font-variant-ligatures: no-common-ligatures;"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(187,44,162)">typealias</span><span style="color:rgb(0,0,0)"> Indices = </span><span style="font-variant-ligatures: no-common-ligatures;">CountableRange</span><span style="color:rgb(0,0,0)">&lt;</span><span style="font-variant-ligatures: no-common-ligatures;">Int32</span><span style="color:rgb(0,0,0)">&gt;</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    </span><span style="color:rgb(187,44,162)">var</span><span style="font-variant-ligatures: no-common-ligatures;"> base: [</span><span style="color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures: no-common-ligatures;">]</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    </span><span style="color:rgb(187,44,162)">var</span><span style="font-variant-ligatures: no-common-ligatures;"> startIndex: </span><span style="color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures: no-common-ligatures;"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">        </span><span style="color:rgb(187,44,162)">return</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(79,129,135)">base</span><span style="font-variant-ligatures: no-common-ligatures;">.</span><span style="color:rgb(112,61,170)">startIndex</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    </span><span style="color:rgb(187,44,162)">var</span><span style="font-variant-ligatures: no-common-ligatures;"> endIndex: </span><span style="color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures: no-common-ligatures;"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">        </span><span style="color:rgb(187,44,162)">return</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(79,129,135)">base</span><span style="font-variant-ligatures: no-common-ligatures;">.</span><span style="color:rgb(112,61,170)">endIndex</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    </span><span style="color:rgb(187,44,162)">func</span><span style="font-variant-ligatures: no-common-ligatures;"> index(after: </span><span style="color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures: no-common-ligatures;">) -&gt; </span><span style="color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures: no-common-ligatures;"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">        </span><span style="color:rgb(187,44,162)">return</span><span style="font-variant-ligatures: no-common-ligatures;"> after + </span><span style="color:rgb(39,42,216)">1</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(187,44,162)">var</span><span style="color:rgb(0,0,0)"> indices: </span><span style="font-variant-ligatures: no-common-ligatures;">CountableRange</span><span style="color:rgb(0,0,0)">&lt;</span><span style="font-variant-ligatures: no-common-ligatures;">Int32</span><span style="color:rgb(0,0,0)">&gt; {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">        </span><span style="color:rgb(187,44,162)">return</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(112,61,170)">CountableRange</span><span style="font-variant-ligatures: no-common-ligatures;">(uncheckedBounds: (lower: </span><span style="color:rgb(112,61,170)">Int32</span><span style="font-variant-ligatures: no-common-ligatures;">(</span><span style="color:rgb(79,129,135)">startIndex</span><span style="font-variant-ligatures: no-common-ligatures;">), upper: </span><span style="color:rgb(112,61,170)">Int32</span><span style="font-variant-ligatures: no-common-ligatures;">(</span><span style="color:rgb(79,129,135)">endIndex</span><span style="font-variant-ligatures: no-common-ligatures;">)))</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    </span><span style="color:rgb(187,44,162)">subscript</span><span style="font-variant-ligatures: no-common-ligatures;">(position: </span><span style="color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures: no-common-ligatures;">) -&gt; </span><span style="color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures: no-common-ligatures;"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">        </span><span style="color:rgb(187,44,162)">get</span><span style="font-variant-ligatures: no-common-ligatures;"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">            </span><span style="color:rgb(187,44,162)">return</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(79,129,135)">base</span><span style="font-variant-ligatures: no-common-ligatures;">[position]</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">        }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">        </span><span style="color:rgb(187,44,162)">set</span><span style="font-variant-ligatures: no-common-ligatures;"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">            </span><span style="color:rgb(79,129,135)">base</span><span style="font-variant-ligatures: no-common-ligatures;">[position] = newValue</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">        }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">}</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"><br></span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"><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">http://stackoverflow.com/questions/37581234/can-an-associated-type-be-restricted-by-protocol-conformance-and-a-where-clause</a></span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-family:arial,sans-serif;font-size:small"><br></span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-family:arial,sans-serif;font-size:small">it&#39;s clearly that we need a syntax like this:</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;"></span><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">public</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color:rgb(187,44,162)">protocol</span><span style="font-variant-ligatures: no-common-ligatures;"> Collection : </span><span style="color:rgb(112,61,170)">Indexable</span><span style="font-variant-ligatures: no-common-ligatures;">, </span><span style="color:rgb(112,61,170)">Sequence</span><span style="font-variant-ligatures: no-common-ligatures;"> {</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;">    </span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="font-variant-ligatures: no-common-ligatures;">/// A sequence that represents a contiguous subrange of the collection&#39;s</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="font-variant-ligatures: no-common-ligatures;">/// elements.</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    </span><span style="color:rgb(0,132,0)">///</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="font-variant-ligatures: no-common-ligatures;">/// This associated type appears as a requirement in the `Sequence`</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="font-variant-ligatures: no-common-ligatures;">/// protocol, but it is restated here with stricter constraints. In a</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="font-variant-ligatures: no-common-ligatures;">/// collection, the subsequence should also conform to `Collection`.</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    </span><span style="color:rgb(187,44,162)">associatedtype</span><span style="font-variant-ligatures: no-common-ligatures;"> SubSequence : IndexableBase, Sequence </span><span style="color:rgb(187,44,162)">where</span><span style="font-variant-ligatures: no-common-ligatures;"> SubSequence.Iterator.Element == Iterator.Element = Slice&lt;</span><span style="color:rgb(187,44,162)">Self</span><span style="font-variant-ligatures: no-common-ligatures;">&gt;</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;">    </span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="font-variant-ligatures: no-common-ligatures;">/// A type that can represent the indices that are valid for subscripting the</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span><span style="font-variant-ligatures: no-common-ligatures;">/// collection, in ascending order.</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">    </span><span style="color:rgb(187,44,162)">associatedtype</span><span style="font-variant-ligatures: no-common-ligatures;"> Indices : IndexableBase, Sequence </span><span style="color:rgb(187,44,162)">where</span><span style="font-variant-ligatures: no-common-ligatures;"> Indices.Iterator.Element == Index = DefaultIndices&lt;</span><span style="color:rgb(187,44,162)">Self</span><span style="font-variant-ligatures: no-common-ligatures;">&gt;</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures;"></span><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo">














</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;">}</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"><span style="font-family:arial,sans-serif;font-size:small"><br></span></span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures: no-common-ligatures;"><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></p></div></div>