<div dir="ltr">I guess the question is, &quot;Do we want this to be the process we expect of and explain to newcomers?&quot;</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 17, 2017 at 7:32 PM, Michel Fortin via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<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 style="word-wrap:break-word"><div style="word-wrap:break-word"><span class=""><div><blockquote type="cite"><div>Le 17 sept. 2017 à 18:00, Félix Cloutier via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="m_4409662905358194403Apple-interchange-newline"><div><div style="word-wrap:break-word">I found that for Sequence, but Sequence is far from the only protocol with default implementations, and not all of them have maintainers willing to write and update documentation to the degree that Apple will.</div></div></blockquote><br></div></span><div><div>How I do it is like this:</div><div><br></div><div>1. Make a dummy struct (or class) that claim conformance to a protocol:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;color:rgb(195,89,0);background-color:rgb(255,252,249)"><span style="color:rgb(54,86,138)">struct</span><span style="color:rgb(0,0,0)"> Z: </span>Collection<span style="color:rgb(0,0,0)"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)">}</div></div><div><br></div><div>2. Compiling, then deciphering the errors tells me that type deduction doesn&#39;t work for associated type `Index` because there is no subscript. So I add one:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;color:rgb(195,89,0);background-color:rgb(255,252,249)"><span style="color:rgb(54,86,138)">struct</span><span style="color:rgb(0,0,0)"> Z: </span>Collection<span style="color:rgb(0,0,0)"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">        </span><span style="color:rgb(54,86,138)">subscript</span> (index: <span style="color:rgb(195,89,0)">Int</span>) -&gt; <span style="color:rgb(195,89,0)">Int</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">                </span><span style="color:rgb(54,86,138)">get</span> { <span style="color:rgb(54,86,138)">return</span> index }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">        </span>}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)">}</div></div><div><br></div><div>3. Compiling again, I now get a suggestion (fixit) telling me to add `startIndex` and `endIndex`. I add the suggested code:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;color:rgb(195,89,0);background-color:rgb(255,252,249)"><span style="color:rgb(54,86,138)">struct</span><span style="color:rgb(0,0,0)"> Z: </span>Collection<span style="color:rgb(0,0,0)"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">        </span><span style="color:rgb(54,86,138)">var</span> startIndex: <span style="color:rgb(195,89,0)">Int</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;background-color:rgb(255,252,249);min-height:14px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">        </span><span style="color:rgb(54,86,138)">var</span> endIndex: <span style="color:rgb(195,89,0)">Int</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;background-color:rgb(255,252,249);min-height:14px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">        </span><span style="color:rgb(54,86,138)">subscript</span> (index: <span style="color:rgb(195,89,0)">Int</span>) -&gt; <span style="color:rgb(195,89,0)">Int</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">                </span><span style="color:rgb(54,86,138)">get</span> { <span style="color:rgb(54,86,138)">return</span> index }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">        </span>}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)">}</div></div><div><br></div><div>4. Compiling again, I get another suggestion (fixit) telling me I&#39;m missing `index(after:)`. I add it and write an implementation inside the braces. And here I am:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;color:rgb(195,89,0);background-color:rgb(255,252,249)"><span style="color:rgb(54,86,138)">struct</span><span style="color:rgb(0,0,0)"> Z: </span>Collection<span style="color:rgb(0,0,0)"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">        </span><span style="color:rgb(54,86,138)">func</span> index(after i: <span style="color:rgb(195,89,0)">Int</span>) -&gt; <span style="color:rgb(195,89,0)">Int</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">                </span><span style="color:rgb(54,86,138)">return</span> i + <span style="color:rgb(54,86,138)">1</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">        </span>}</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;background-color:rgb(255,252,249);min-height:14px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">        </span><span style="color:rgb(54,86,138)">var</span> startIndex: <span style="color:rgb(195,89,0)">Int</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;background-color:rgb(255,252,249);min-height:14px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">        </span><span style="color:rgb(54,86,138)">var</span> endIndex: <span style="color:rgb(195,89,0)">Int</span></div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;background-color:rgb(255,252,249);min-height:14px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">        </span><span style="color:rgb(54,86,138)">subscript</span> (index: <span style="color:rgb(195,89,0)">Int</span>) -&gt; <span style="color:rgb(195,89,0)">Int</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">                </span><span style="color:rgb(54,86,138)">get</span> { <span style="color:rgb(54,86,138)">return</span> index }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)"><span class="m_4409662905358194403Apple-tab-span" style="white-space:pre-wrap">        </span>}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Mono&#39;;background-color:rgb(255,252,249)">}</div></div><div><br></div><div>5. And now it compiles. Hurray!</div><div><br></div><div>I made a collection type and did not have to read any documentation at all. The hardest step is the first one where you have to figure out how to make deduction work for the associated types based on the error messages.</div><span class="HOEnZb"><font color="#888888"><div><br></div></font></span></div><span class="HOEnZb"><font color="#888888"><br><div><div style="word-wrap:break-word"><div style="word-wrap:break-word"><div style="word-wrap:break-word"><div style="font-family:Helvetica;font-variant-ligatures:normal;font-variant-east-asian:normal;line-height:normal;text-align:-webkit-auto;word-wrap:break-word"><span class="m_4409662905358194403Apple-style-span" style="border-collapse:separate;font-variant-ligatures:normal;font-variant-east-asian:normal;line-height:normal;border-spacing:0px"><div style="word-wrap:break-word"><span class="m_4409662905358194403Apple-style-span" style="border-collapse:separate;font-variant-ligatures:normal;font-variant-east-asian:normal;line-height:normal;text-align:-webkit-auto;border-spacing:0px"><div style="word-wrap:break-word"><span class="m_4409662905358194403Apple-style-span" style="border-collapse:separate;font-variant-ligatures:normal;font-variant-east-asian:normal;line-height:normal;text-align:-webkit-auto;border-spacing:0px"><div style="word-wrap:break-word">-- <br>Michel Fortin</div><div style="word-wrap:break-word"><span style="text-align:-webkit-auto"><a href="https://michelf.ca/" target="_blank">https://michelf.ca</a></span></div><div><br></div></span></div></span></div></span></div></div></div></div></div></font></span></div></div><span class="HOEnZb"><font color="#888888"><br><br><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><span class="m_4409662905358194403Apple-style-span" style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px"><div style="word-wrap:break-word"><span class="m_4409662905358194403Apple-style-span" style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px"><div style="word-wrap:break-word"><span class="m_4409662905358194403Apple-style-span" style="border-collapse:separate;color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px"><div style="word-wrap:break-word">-- <br>Michel Fortin</div><div style="word-wrap:break-word"><span style="text-align:-webkit-auto"><a href="https://michelf.ca" target="_blank">https://michelf.ca</a></span></div></span></div></span></div></span></div></div></div></div>
</div>
<br></font></span></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>