<div dir="ltr">Does enabling a lot of small improvements that make APIs more ergonomic count as practical?</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 25, 2016 at 12:19 PM, Xiaodi Wu <span dir="ltr">&lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class="">On Sun, Dec 25, 2016 at 3:07 PM, Adam Nemecek <span dir="ltr">&lt;<a href="mailto:adamnemecek@gmail.com" target="_blank">adamnemecek@gmail.com</a>&gt;</span> wrote:<br></span><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">There&#39;s a book that provides quite a bit of info on this <div><br></div><div><a href="https://smile.amazon.com/Elements-Programming-Alexander-Stepanov/dp/032163537X?sa-no-redirect=1" target="_blank">https://smile.amazon.com/Eleme<wbr>nts-Programming-Alexander-<wbr>Stepanov/dp/032163537X?sa-no-<wbr>redirect=1</a><br></div><div><br></div><div>They say that DefaultConstructible is one of the essential protocols on which most algorithms rely in one way or another. One of the authors is the designer of the C++ STL and basically the father of modern generics.</div><div><br></div><div>This protocol is important for any algebraic structure that deals with the concept of appending or addition (as &quot;zero&quot; is one of the requirements of monoid). There isn&#39;t a good short answer to your question. It&#39;s a building block of algorithms. Think about why a RangeReplaceableCollection can provide you with a default constructor but a Collection can&#39;t. </div><div><span style="color:rgb(80,0,80)"></span></div></div></blockquote><div><br></div></span><div>It&#39;s well and fine that most algorithms rely on the concept in one way or another. Yet the Swift standard library already implements many generic algorithms but has no DefaultConstructible, presumably because there are other protocols that guarantee `init()` and the algorithms being implemented don&#39;t need to be (practically speaking) generic over all DefaultConstructible types. My question is: what practical use cases are there for an explicit DefaultConstructible that are impractical today?</div><span class=""><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><span style="color:rgb(80,0,80)">On Sun, Dec 25, 2016 at 11:37 AM, Xiaodi Wu </span><span dir="ltr" style="color:rgb(80,0,80)">&lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt;</span><span style="color:rgb(80,0,80)"> wrote:</span><br></div></div><div class="m_8912025549324475289HOEnZb"><div class="m_8912025549324475289h5"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Can you give some other examples of generic algorithms that would make use of this DefaultConstructible? I&#39;m having trouble coming up with any other than reduce.<br><div class="gmail_quote"><div><div class="m_8912025549324475289m_699475458640075951h5"><div dir="ltr">On Sun, Dec 25, 2016 at 14:23 Adam Nemecek via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_8912025549324475289m_699475458640075951h5"><div dir="ltr" class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">This protocol is present in C++ <a href="http://en.cppreference.com/w/cpp/concept/DefaultConstructible" class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg" target="_blank">http://en.cppreference.com<wbr>/w/cpp/concept/DefaultConstruc<wbr>tible</a> as well as in Rust <a href="https://doc.rust-lang.org/std/default/" class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg" target="_blank">https://doc.rust-lang.org/std/<wbr>default/</a><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">It&#39;s the identity element/unit of a monoid or a zero.<br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">The Swift implementation is very simple (I&#39;m open to different names)<br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">protocol DefaultConstructible {</div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">    init() </div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">}</div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">A lot of the standard types could then be made to conform to this protocol. These include all the numeric types, collection types (array, set, dict), string, basically at least every type that currently has a constructor without any arguments.</div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">The RangeReplaceableCollection protocol would inherit from this protocol as well. <br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">This protocol would simplify a lot of generic algorithms where you need the concept of a zero (which shows up a lot)</div></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">Once introduced, Sequence could define an alternative implementation of reduce where the initial result doesn&#39;t need to be provided as it can be default constructed.</div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div><div class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg"></div></div></div></div></div>
______________________________<wbr>_________________<br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">
swift-evolution mailing list<br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br class="m_8912025549324475289m_699475458640075951m_-6015751673947924360gmail_msg">
</blockquote></div>
</blockquote></div><br></div>
</div></div></blockquote></span></div><br></div></div>
</blockquote></div><br></div>