<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">On Dec 26, 2016, at 12:10, Tony Allevato &lt;<a href="mailto:tony.allevato@gmail.com" class="">tony.allevato@gmail.com</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div dir="ltr" class="">On Mon, Dec 26, 2016 at 11:57 AM David Sweeris via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">On Dec 26, 2016, at 11:35, Tony Allevato &lt;<a href="mailto:allevato@google.com" class="gmail_msg" target="_blank">allevato@google.com</a>&gt; wrote:<br class="gmail_msg"><br class="gmail_msg"></div><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">Mathematically, identities are associated with (type, operation) pairs, not types alone.<br class="gmail_msg"><br class="gmail_msg">This conversation has put me in the column of "numeric types shouldn't have default initializers at all", personally.
</div></blockquote><br class="gmail_msg"></div><div dir="auto" class="gmail_msg"><div class="gmail_msg">I'd agree, except sometimes you need a T, <i class="gmail_msg">any</i> T, for when you want to create a "pre-sized" array for stuffing results into by index:</div><div class="gmail_msg">for i in ... {</div><div class="gmail_msg">&nbsp; &nbsp; a[i] = ...</div><div class="gmail_msg">}</div><div class="gmail_msg">Simply saying "var a =[T](); a.reserveCapacity()" doesn't cut it because it'll still crash if you try to store anything in a[i] without somehow putting at least i+1 elements in the array first.</div></div></blockquote><div class=""><br class=""></div><div class="">Array already has init(repeating:count:) that puts the responsibility of choosing the default value at the call site. If someone were writing a generic algorithm around this, then why not just propagate that responsibility out to its call site as well? That way, the algorithm isn't making any assumptions about what the "default" value is or even if one exists, and it doesn't impose additional requirements on the element type. For example, the user could get the default from a static factory method, an instance method on another object, or something else entirely.</div></div></div>
</blockquote><br class=""><div class="">Yeah, that's what I would use… The "filled out" example would be:</div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; color: rgb(187, 44, 162); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Array</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div></div></div></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">public</span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> pmap&lt;T: </span><span style="color: rgb(79, 129, 135); font-variant-ligatures: no-common-ligatures;" class="">DefaultInitable</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&gt; (transform: (</span><span style="color: rgb(112, 61, 170); font-variant-ligatures: no-common-ligatures;" class="">Element</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) -&gt; </span><span style="color: rgb(79, 129, 135); font-variant-ligatures: no-common-ligatures;" class="">T</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) -&gt; [</span><span style="color: rgb(79, 129, 135); font-variant-ligatures: no-common-ligatures;" class="">T</span><span style="font-variant-ligatures: no-common-ligatures;" class="">] {</span></div></div></div></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> result = </span><span style="color: rgb(112, 61, 170); font-variant-ligatures: no-common-ligatures;" class="">Array</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&lt;</span><span style="color: rgb(79, 129, 135); font-variant-ligatures: no-common-ligatures;" class="">T</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&gt;(repeating:</span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="color: rgb(79, 129, 135); font-variant-ligatures: no-common-ligatures;" class="">T</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(), count: </span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">self</span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="color: rgb(112, 61, 170); font-variant-ligatures: no-common-ligatures;" class="">count</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span><span style="color: rgb(0, 132, 0); font-variant-ligatures: no-common-ligatures;" class="">//Pick a T... any T...</span></div></div></div></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">for</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> i </span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">in</span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">self</span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="color: rgb(112, 61, 170); font-variant-ligatures: no-common-ligatures;" class="">indices</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div></div></div></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result[i] =<font color="#bb2ca2" class=""> </font></span><span style="color: rgb(49, 89, 93); font-variant-ligatures: no-common-ligatures;" class="">whateverTheConcurrentExectutionSyntaxIs</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">self</span><span style="font-variant-ligatures: no-common-ligatures;" class="">[i</span><span style="font-variant-ligatures: no-common-ligatures;" class="">], </span><span style="font-variant-ligatures: no-common-ligatures;" class="">transform</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div></div></div></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#bb2ca2" class="">&nbsp; &nbsp; &nbsp; &nbsp; </font>}</span></div></div></div></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> result</span></div></div></div></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; }</span></div></div></div></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div></div></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="color: rgb(187, 44, 162); font-variant-ligatures: no-common-ligatures;" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> thisCouldTakeAWhile = </span><span style="color: rgb(112, 61, 170); font-variant-ligatures: no-common-ligatures;" class="">Array</span><span style="font-variant-ligatures: no-common-ligatures;" class="">((</span><span style="color: rgb(39, 42, 216); font-variant-ligatures: no-common-ligatures;" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class="">...</span><span style="color: rgb(39, 42, 216); font-variant-ligatures: no-common-ligatures;" class="">10000</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)).</span><span style="color: rgb(49, 89, 93); font-variant-ligatures: no-common-ligatures;" class="">pmap</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div></div></div></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; color: rgb(49, 89, 93); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">someReallySlowFunction</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">($0)</span></div></div></div></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Menlo; margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div></div></div></div></blockquote><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">At least I <i class="">think</i> that’d work... I haven’t tried it yet... Anyway, without some way (<i class="">any</i> way) of getting an instance of T to fill in the `result` array, it becomes much trickier to keep track of all the concurrently-calculated transformed values. In this case, the semantics of `T()` are fairly&nbsp;irrelevant because the semantics of the <i class="">overall statement</i> is just to work around</span>&nbsp;a language limitation (Swift not having separate allocation and initialization phases), which doesn’t have anything to do with the semantics of the initial value that got passed as the `repeating` argument.</div></div></div></div><div class=""><br class=""></div><div class="">- Dave Sweeris</div></body></html>