<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 16, 2017, at 4:38 PM, Howard Lovatt &lt;<a href="mailto:howard.lovatt@gmail.com" class="">howard.lovatt@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><font face="Helvetica" class=""><span style="font-size:12px" class="">When the user writes:</span></font></div><div class=""><font face="Helvetica" class=""><span style="font-size:12px" class=""><br class=""></span></font></div><div class=""><font face="Helvetica" class=""><span style="font-size:12px" class="">&nbsp; &nbsp; let increment: &lt;T&gt;(T) throws -&gt; T where T: Numeric = { $0 + 1 }</span></font></div><div class=""><font face="Helvetica" class=""><span style="font-size:12px" class="">&nbsp; &nbsp; increment(1) // 2</span></font></div><div class=""><font face="Helvetica" class=""><span style="font-size:12px" class="">&nbsp; &nbsp; increment(1.1) // 2.1</span></font></div></div></div></blockquote><div><br class=""></div><div>This means that ‘increment’ is a *value* with a generic function type. Presumably you want to pass generic closures as function parameters and results too. This is called higher-rank polymorphism and it introduces considerable complexity in type checking and code generation.</div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="">Compiler issues global struct as above. Then:</div><div class=""><font face="Helvetica" class=""><span style="font-size:12px" class=""><br class=""></span></font></div><div class=""><font face="Helvetica" class=""><span style="font-size:12px" class="">&nbsp; &nbsp;&nbsp;let _int_increment = _Function1__T1__T1__T1__E__Numeric&lt;Int&gt;({ $0 + 1 })</span></font></div><div class=""><font face="Helvetica" class=""><span style="font-size:12px" class="">&nbsp; &nbsp; try _int_increment.call(1) // 2</span></font></div><div class=""><font face="Helvetica" class=""><span style="font-size:12px" class="">&nbsp; &nbsp; let _double_increment = _Function1__T1__T1__T1__E__Numeric&lt;Double&gt;({ $0 + 1 })</span></font></div><div class=""><font face="Helvetica" class=""><span style="font-size:12px" class="">&nbsp; &nbsp; try _double_increment.call(1.1) // 2.1</span></font></div></div></blockquote><div><br class=""></div><div>What if I do,</div><div><br class=""></div><div>let array = [increment]</div><div><br class=""></div><div>What is the type of ‘array’?</div><div><br class=""></div><div>Slava</div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class=""><font face="Helvetica" class=""><span style="font-size:12px" class="">The more restrictive form that you suggest (I think this is what you mean anyway) of only allowed locally, not globally, is easier to name mangle, you just need a unique name, nothing about the name needs to be canonical. This would be similar to local functions at present and would be useful (though I am not sure how many local *generic* functions there are).</span></font></div></div></blockquote><blockquote type="cite" class=""><div dir="ltr" class=""><div class=""><font face="Helvetica" class=""><span style="font-size:12px" class=""><br class=""></span></font></div></div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature">&nbsp; -- Howard.<br class=""></div></div>
<br class=""><div class="gmail_quote">On 17 November 2017 at 10:47, Slava Pestov <span dir="ltr" class="">&lt;<a href="mailto:spestov@apple.com" target="_blank" class="">spestov@apple.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Nov 16, 2017, at 3:07 PM, Howard Lovatt via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_-5744858107293221082Apple-interchange-newline"><div class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Where I am proposing a change is that if a closure with generic arguments is encountered it is transformed into the equivalent struct and the struct is typed as it currently is (or if there is a better implementation something equivalent to this), therefore zero change to the type system.</div></div></blockquote><div class=""><br class=""></div>Since we already have local functions that can capture values and be generic, there’s no need to implement a new mechanism for name mangling or handling of captures.</div><div class=""><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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class=""></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">The changes proposed are a transformation into a struct and name mangling, e.g.:</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class=""></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div class="">&nbsp; &nbsp; let increment: &lt;T&gt;(T) throws -&gt; T where T: Numeric = { $0 + 1 }</div></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div class="">&nbsp; &nbsp; let increment = { &lt;T&gt;(n: T) throws -&gt; T where T: Numeric in n + 1 }</div></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div class="">&nbsp; &nbsp; let increment: &lt;T&gt;(T) throws -&gt; T where T: Numeric = { &lt;T&gt;(n: T) throws -&gt; T where T: Numeric in n + 1 }</div></div></div></blockquote></div><br class=""><div class="">It sounds like what you’re proposing is essentially a new surface syntax for local functions — since a generic closure would not be a first class value, it could not appear anywhere except for the right hand side of a let binding, right?</div><span class="HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">Slava</div></font></span></div></blockquote></div><br class=""></div>
</blockquote></div><br class=""></body></html>