Can you give some other examples of generic algorithms that would make use of this DefaultConstructible? I'm having trouble coming up with any other than reduce.<br><div class="gmail_quote"><div dir="ltr">On Sun, Dec 25, 2016 at 14:23 Adam Nemecek via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">This protocol is present in C++ <a href="http://en.cppreference.com/w/cpp/concept/DefaultConstructible" class="gmail_msg" target="_blank">http://en.cppreference.com/w/cpp/concept/DefaultConstructible</a> as well as in Rust <a href="https://doc.rust-lang.org/std/default/" class="gmail_msg" target="_blank">https://doc.rust-lang.org/std/default/</a><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">It's the identity element/unit of a monoid or a zero.<br class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg">The Swift implementation is very simple (I'm open to different names)<br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">protocol DefaultConstructible {</div><div class="gmail_msg"> init() </div><div class="gmail_msg">}</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The RangeReplaceableCollection protocol would inherit from this protocol as well. <br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Once introduced, Sequence could define an alternative implementation of reduce where the initial result doesn't need to be provided as it can be default constructed.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div></div></div>
_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>