<html><head><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="">A few more comments inlined now that I’ve read it.</div><br class=""><div><blockquote type="cite" class=""><div class="">On May 30, 2016, at 7:44 AM, plx via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="">- if you have e.g. 2+ packs, can you enforce (T…) and (U…) have the same arity?</div></div></div></blockquote><div><br class=""></div><div>Seems the answer is yes iff there’s a `T.Foo... == U.Bar…` style relationship, but no way to just request same-arity by itself?</div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="">- if you have e.g. 2+ packs, could you enforce e.g. T.Foo… == U.Bar ?</div></div></div></blockquote><div><br class=""></div><div>Missed this either before or you added it, sorry either way.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><br class=""></div><div class="">…as always nice-to-have, but throwing them out there for consideration.</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="">I'll write something up.</div></div></div></blockquote></div></div></blockquote><div><br class=""></div><div>I like the `fold` construct but feel like for this use it needs a few more options-or-variants.</div><div><br class=""></div><div>The first one is some more-explicit support for “early exit”.</div><div><br class=""></div><div>EG for the cascading-lookup example, you can convert it to this `#fold`:</div><div><br class=""></div><div><div class="">&nbsp; private func lookupKey(key: K) -&gt; V? {</div><div class="">&nbsp; &nbsp; return #fold(</div><div class="">&nbsp; &nbsp; &nbsp; start: nil,</div><div class="">&nbsp; &nbsp; &nbsp; reducer: {&nbsp;</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; (table, value)</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; in</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; return value ?? table[key]</div><div class="">&nbsp; &nbsp; &nbsp; },</div><div class="">&nbsp; &nbsp; &nbsp; values: tables</div><div class="">&nbsp; &nbsp; )</div><div class="">&nbsp; }</div><div class=""><br class=""></div><div class="">…but unless the compiler is very savvy you are going to have a bunch of unneeded stuff even after your “success” (it won’t do another lookup, but it just seems wasteful and could be wasteful in other contexts).</div><div class=""><br class=""></div><div class="">Relatedly, that `#fold` is only going to work if the compiler can infer a proper type for the `table` argument to the `reducer`.</div><div class=""><br class=""></div><div class="">If you have to specify the types explicitly via a helper function, it seems like this won’t work:</div><div class=""><br class=""></div><div class=""><div class="">&nbsp; func lookupIfNecessary&lt;T:LookupTable where T.Key == K, T.Value == V&gt;(table: T, &nbsp;key: K, value: V?) -&gt; V? {</div><div class="">&nbsp; &nbsp; &nbsp;return value ?? table[key]</div><div class="">&nbsp; }</div></div><div class=""><br class=""></div><div class="">…b/c the signature isn’t right for the reducer, and it seems like this might work:</div><div class=""><br class=""></div><div class=""><div class="">&nbsp; func createLookupFunction&lt;T:LookupTable where T.Key == K, T.Value == V&gt;(key: K) -&gt; (T, V?) -&gt; V? {</div><div class="">&nbsp; &nbsp; &nbsp;return { (t,v) in return v ?? t[key] }</div><div class="">&nbsp; }</div></div><div class=""><br class=""></div><div class=""><div class=""><div class="">&nbsp; private func lookupKey(key: K) -&gt; V? {</div><div class="">&nbsp; &nbsp; return #fold(</div><div class="">&nbsp; &nbsp; &nbsp; start: nil,</div><div class="">&nbsp; &nbsp; &nbsp; reducer: createLookupFunction(key), // &lt;- should work…I hope...</div><div class="">&nbsp; &nbsp; &nbsp; values: tables</div><div class="">&nbsp; &nbsp; )</div><div class="">&nbsp; }</div></div><div class=""><br class=""></div><div class="">…but it seems a bit convoluted; perhaps there’s a trick here? Or perhaps a variant with an adjusted signature like so:</div><div class=""><br class=""></div><div class="">&nbsp; // perhaps inout K ? or as an option?</div><div class="">&nbsp; #foldWithContext(context: K, start: U, reducer:(#requirements,U,K) -&gt; U, values: (T…)) -&gt; U</div><div class=""><br class=""></div><div class="">Relatedly, having `#fold` variants like the above that include the current index could address a lot of the uses for integer-based indexing:</div><div class=""><br class=""></div><div class="">&nbsp; #indexedFold(start: U, reducer:(#requirements,U,Int) -&gt; U, values: (T…)) -&gt; U</div><div class=""><br class=""></div><div class="">…(the above can be done w/out dedicated support, but dedicated support might be more compiler-friendly on this one).</div><div class=""><br class=""></div><div class="">Finally, after reading it over again I really find the `…` confusing beyond the initial declaration sites (as you can perhaps tell since I’ve been mis-using it in my replies).</div><div class=""><br class=""></div><div class="">I can’t come up with an alternative that isn’t a major regression for simple declarations, but if a more-explicit syntax could be invented I’d highly prefer it.</div><div class=""><br class=""></div></div></div><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On May 28, 2016, at 3:03 PM, Austin Zheng via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hello swift-evolution,<div class=""><br class=""></div></div></div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>