<div dir="ltr"><div class="gmail_quote"><div dir="ltr">I&#39;m totally +1 with this pitch and was going to draft it myself. Though, since it&#39;s here let&#39;s pull it off.<div><br></div><div>Let&#39;s bring the same Functor (event considering it&#39;s not a _real_ functor) example from higher-kinded types:</div><div><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)"><span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">protocol</span> <span class="m_-5073191882453072503gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Functor</span> {
  <span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">associatedtype</span> <span class="m_-5073191882453072503gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">A</span>
  <span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_-5073191882453072503gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">fmap</span>&lt;<span class="m_-5073191882453072503gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">FB</span> <span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">where</span> FB ~= <span class="m_-5073191882453072503gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Self</span>&gt;(<span class="m_-5073191882453072503gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)"><span class="m_-5073191882453072503gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">f</span></span>: A <span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">-&gt;</span> FB.A) <span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">-&gt;</span> FB
}</pre></div><div><br></div><div>And make it a functor:</div><div><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)"><span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">protocol</span> <span class="m_-5073191882453072503gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Functor</span> {
  <span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">associatedtype</span> <span class="m_-5073191882453072503gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">A</span></pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span style="color:rgb(36,41,46);font-size:13.6px">  </span><span class="m_-5073191882453072503gmail-pl-k" style="font-size:13.6px;box-sizing:border-box;color:rgb(167,29,93)">associatedtype</span><span style="color:rgb(36,41,46);font-size:13.6px"> </span><span style="font-size:13.6px"><font color="#0086b3">F&lt;B&gt; : </font></span>Functor where Functor.A == B</pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="m_-5073191882453072503gmail-pl-k" style="color:rgb(167,29,93);box-sizing:border-box"><br></span></pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box">  </span><span class="m_-5073191882453072503gmail-pl-k" style="color:rgb(167,29,93);box-sizing:border-box">func</span><font color="#24292e"> </font><span class="m_-5073191882453072503gmail-pl-en" style="color:rgb(121,93,163);box-sizing:border-box">map</span><font color="#24292e">&lt;</font><span class="m_-5073191882453072503gmail-pl-c1" style="color:rgb(0,134,179);box-sizing:border-box">B</span><font color="#24292e">&gt;(</font><span class="m_-5073191882453072503gmail-pl-smi" style="color:rgb(51,51,51);box-sizing:border-box"><span class="m_-5073191882453072503gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">f</span></span><font color="#24292e">: (A) </font><span class="m_-5073191882453072503gmail-pl-k" style="color:rgb(167,29,93);box-sizing:border-box">-&gt;</span><font color="#24292e"> B) </font><span class="m_-5073191882453072503gmail-pl-k" style="color:rgb(167,29,93);box-sizing:border-box">-&gt;</span><font color="#24292e"> F&lt;B&gt;
}</font></pre></div><div>Now we can implement it in a concrete class the way we want:</div><div><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)"><span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">protocol</span> <span class="m_-5073191882453072503gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Array</span> {
  <span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">typealias</span> <span class="m_-5073191882453072503gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">A = Element</span></pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span style="color:rgb(36,41,46);font-size:13.6px">  </span><span class="m_-5073191882453072503gmail-pl-k" style="font-size:13.6px;box-sizing:border-box;color:rgb(167,29,93)">typealis</span><span style="color:rgb(36,41,46);font-size:13.6px"> </span><span style="font-size:13.6px"><font color="#0086b3">F&lt;B&gt; = Array&lt;B&gt; </font></span>//Our where clause fits ok: Functor.A == B;</pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal">//Keep in mind we are free to use another class instead of Array and it still will work.</pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal">//This is the difference with higher-kinded.</pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal">//I&#39;m not saying higher-kinded is bad, I&#39;m saying I would love to have both :)</pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box">  </span><span class="m_-5073191882453072503gmail-pl-k" style="color:rgb(167,29,93);box-sizing:border-box">func</span><font color="#24292e"> </font><span class="m_-5073191882453072503gmail-pl-en" style="color:rgb(121,93,163);box-sizing:border-box">map</span><font color="#24292e">&lt;</font><span class="m_-5073191882453072503gmail-pl-c1" style="color:rgb(0,134,179);box-sizing:border-box">B</span><font color="#24292e">&gt;(</font><span class="m_-5073191882453072503gmail-pl-smi" style="color:rgb(51,51,51);box-sizing:border-box"><span class="m_-5073191882453072503gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">f</span></span><font color="#24292e">: (A) </font><span class="m_-5073191882453072503gmail-pl-k" style="color:rgb(167,29,93);box-sizing:border-box">-&gt;</span><font color="#24292e"> B) </font><span class="m_-5073191882453072503gmail-pl-k" style="color:rgb(167,29,93);box-sizing:border-box">-&gt;</span><font color="#24292e"> F&lt;B&gt; {</font></pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><font color="#24292e">  //implementation details</font></pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><font color="#24292e">  }
}</font></pre></div><div>The benefit here is that we can use the protocol, use its map in other places. I.e.</div><div><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal;color:rgb(36,41,46)"><span class="m_-5073191882453072503gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">protocol</span> <span class="m_-5073191882453072503gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Monad : Functor</span> {
  </pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><span class="m_-5073191882453072503gmail-pl-k" style="color:rgb(167,29,93);box-sizing:border-box">  func</span><font color="#24292e"> flatM</font><span class="m_-5073191882453072503gmail-pl-en" style="color:rgb(121,93,163);box-sizing:border-box">ap</span><font color="#24292e">&lt;</font><span class="m_-5073191882453072503gmail-pl-c1" style="color:rgb(0,134,179);box-sizing:border-box">M : Monad</span><font color="#24292e">&gt;(</font><span class="m_-5073191882453072503gmail-pl-smi" style="color:rgb(51,51,51);box-sizing:border-box"><span class="m_-5073191882453072503gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">f</span></span><font color="#24292e">: (A) </font><span class="m_-5073191882453072503gmail-pl-k" style="color:rgb(167,29,93);box-sizing:border-box">-&gt;</span><font color="#24292e"> M) </font><span class="m_-5073191882453072503gmail-pl-k" style="color:rgb(167,29,93);box-sizing:border-box">-&gt;</span><font color="#24292e"> M {</font></pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><font color="#24292e">     //pseudo code</font></pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><font color="#24292e">     return flatten(map(f: f))</font></pre><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-radius:3px;word-break:normal"><font color="#24292e">  }
}</font></pre></div><div>and further... extend Monad, create Applicative, etc.</div><div><br></div><div>Does it make sense now?</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Sun, Mar 12, 2017 at 10:39 AM, Xiaodi Wu via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div class="m_-5073191882453072503h5">On Sun, Mar 12, 2017 at 3:23 AM, Karl Wagner <span dir="ltr">&lt;<a href="mailto:razielim@gmail.com" target="_blank">razielim@gmail.com</a>&gt;</span> wrote:<br></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div class="m_-5073191882453072503h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div class="m_-5073191882453072503m_-3038253098502344554h5"><br><div><blockquote type="cite"><div>On 12 Mar 2017, at 09:11, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623Apple-interchange-newline"><div><div dir="ltr" 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">On Sun, Mar 12, 2017 at 3:02 AM, Karl Wagner<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623Apple-converted-space"> </span><span dir="ltr">&lt;<a href="mailto:razielim@gmail.com" target="_blank">razielim@gmail.com</a>&gt;</span><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623Apple-converted-space"> </span>wr<wbr>ote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623h5"><br><div><blockquote type="cite"><div>On 12 Mar 2017, at 08:50, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-interchange-newline"><div><div dir="ltr" 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">On Sun, Mar 12, 2017 at 1:39 AM, Karl Wagner<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span><span dir="ltr">&lt;<a href="mailto:razielim@gmail.com" target="_blank">razielim@gmail.com</a>&gt;</span><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>wr<wbr>ote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885gmail-"><br><div><blockquote type="cite"><div>On 12 Mar 2017, at 08:21, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885gmail-m_-5255648766755841190Apple-interchange-newline"><div><div dir="ltr">Sorry, I&#39;m confused. The following works:<div><br></div><div>```</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">protocol</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>Promise {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures"> <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures">associatedtype</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>Result</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">protocol</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>Scanner {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"> <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">associatedtype</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>ScannerPromis<wbr>e : Promise</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"> <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>frobnicate&lt;T&gt;(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">_</span><span style="font-variant-ligatures:no-common-ligatures">:<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">T</span><span style="font-variant-ligatures:no-common-ligatures">) -&gt; ScannerPromise</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">   <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">where</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>ScannerPromise.Result ==<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">T</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div>```</div><div><br></div><div>Why does it matter if `ScannerPromise` is generic or not?</div><div class="gmail_extra"><br></div></div></div></blockquote></div><br></span><div>That’s some pretty strange syntax. I admit I didn’t even try that. ScannerPromise would necessarily have to be generic in this context, because I want to bind one of its associated types to a generic parameter from a function. There is no way a non-generic type could do that.</div><div><br></div><div>That said, even though the compiler accepts your code, it doesn’t seem to actually work:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="Courier">protocol Promise {</font></div></div><div><div><font face="Courier"> <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>associatedtype Result</font></div></div><div><div><font face="Courier"> <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>func await() -&gt; Result</font></div></div><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885gmail-"><div><div><font face="Courier">}</font></div></div><div><div><font face="Courier"><br></font></div></div><div><div><font face="Courier">protocol Scanner {</font></div></div><div><div><font face="Courier"> <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>associatedtype ScannerPromise : Promise</font></div></div><div><div><font face="Courier"> <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>func frobnicate&lt;T&gt;(_: T) -&gt; ScannerPromise</font></div></div><div><div><font face="Courier">   <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>where ScannerPromise.Result == T</font></div></div><div><div><font face="Courier">}</font></div></div><div><div><font face="Courier"><br></font></div></div></span><div><div><font face="Courier">func use&lt;S: Scanner, T&gt;(_ s: S, _ t: T) -&gt; T {</font></div></div><div><div><font face="Courier"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885gmail-m_-5255648766755841190Apple-tab-span" style="white-space:pre-wrap">        </span>return s.frobnicate(t).await()</font></div></div><div><div><font face="Courier">}</font></div></div></blockquote><div><div><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885gmail-m_-5255648766755841190Apple-tab-span" style="white-space:pre-wrap">        </span><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>   </div></div><div><br></div><div>3.0.2: Segfault</div><div><br></div><div>3.1:</div><div><br></div><div>error: repl.swift:13:14: error: cannot invoke &#39;frobnicate&#39; with an argument list of type &#39;(T)&#39;<br>    return s.frobnicate(t).await()<br>             ^<br><br>repl.swift:13:14: note: expected an argument list of type &#39;(T)&#39;<br>    return s.frobnicate(t).await()</div></div></blockquote><div><br></div><div>That&#39;s because your `T` in `use` has no relationship with your `T` in `protocol Scanner`; you just happen to have chosen the same letter of the alphabet. This becomes clear if you rename:</div><div><br></div><div>```</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>use&lt;S:<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Scanner</span><span style="font-variant-ligatures:no-common-ligatures">, U&gt;(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">_</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>s:<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">S</span><span style="font-variant-ligatures:no-common-ligatures">,<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">_</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>t:<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">U</span><span style="font-variant-ligatures:no-common-ligatures">) -&gt;<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">U</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"> <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">return</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>s.frobnicate(t).await<wbr>()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"><b>// cannot invoke &#39;frobnicate&#39; with an argument list of type &#39;(U)&#39;</b></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><b>// expected an argument list of type &#39;(T)&#39;</b><br></div></div><div>```</div><div><br></div><div>However, this works:</div><div><br></div><div>```</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>use&lt;S:<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Scanner</span><span style="font-variant-ligatures:no-common-ligatures">, T&gt;(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">_</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>s:<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">S</span><span style="font-variant-ligatures:no-common-ligatures">,<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">_</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>t:<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">T</span><span style="font-variant-ligatures:no-common-ligatures">) -&gt;<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">T</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"> <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">where</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">S</span><span style="font-variant-ligatures:no-common-ligatures">.ScannerPromise.Resul<wbr>t ==<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">T</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(49,89,93)"><span style="font-variant-ligatures:no-common-ligatures"> <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">return</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>s.</span><span style="font-variant-ligatures:no-common-ligatures">frobnicate</span><span style="font-variant-ligatures:no-common-ligatures">(t).</span><span style="font-variant-ligatures:no-common-ligatures">await</span><span style="font-variant-ligatures:no-common-ligatures"><wbr>()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div>```</div><div><br></div><div>...or just this:</div><div><br></div><div>```</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>use&lt;S:<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Scanner</span><span style="font-variant-ligatures:no-common-ligatures">&gt;(</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)"> <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623Apple-converted-space"> </span>_</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>s:<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">S</span><span style="font-variant-ligatures:no-common-ligatures">,<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">_</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>t:<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">S</span><span style="font-variant-ligatures:no-common-ligatures">.ScannerPromis<wbr>e.Result</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">) -&gt;<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">S</span><span style="font-variant-ligatures:no-common-ligatures">.ScannerPromise.Result {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(49,89,93)"><span style="font-variant-ligatures:no-common-ligatures"> <span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">return</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-converted-space"> </span>s.</span><span style="font-variant-ligatures:no-common-ligatures">frobnicate</span><span style="font-variant-ligatures:no-common-ligatures">(t).</span><span style="font-variant-ligatures:no-common-ligatures">await</span><span style="font-variant-ligatures:no-common-ligatures"><wbr>()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div>```</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885gmail-HOEnZb"><font color="#888888"><div></div><div>- Karl</div></font></span></div></blockquote></div></div></div></div></blockquote></div><br></div></div><div>No, what you’ve done is something different. “frobnicate” is itself a generic function, so it should work if you rename the parameter to “U&quot;. You’ve just punted the constraint down the abstraction hierarchy.</div><div><br></div><div>This becomes clear if you try to continue working at the protocol-level:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="Courier">extension Scanner {</font></div><div><font face="Courier"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-tab-span" style="white-space:pre-wrap">        </span>func synchronised_frob&lt;T&gt;(_ t: T) -&gt; T {</font></div><div><font face="Courier"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-tab-span" style="white-space:pre-wrap">        </span><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623Apple-converted-space"> </span>   return frobnicate(t).await()</font></div><div><font face="Courier"><span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623m_4681716977856857885Apple-tab-span" style="white-space:pre-wrap">        </span>}</font></div><div><font face="Courier">}</font></div></blockquote><div><br></div><div>error: repl.swift:14:16: error: cannot invoke &#39;frobnicate&#39; with an argument list of type &#39;(T)&#39;<br>        return frobnicate(t).await()<br>               ^<br><br>repl.swift:14:16: note: expected an argument list of type &#39;(T)&#39;<br>        return frobnicate(t).await()<span class="m_-5073191882453072503m_-3038253098502344554m_1210020992260782623HOEnZb"><font color="#888888"><br><br></font></span></div></div></blockquote><div><br></div><div>Hmm, I&#39;m not sure what you&#39;re trying to accomplish here. If I have an instance `s` that conforms to `Scanner`, then it must have a concrete associated type `ScannerPromise.Result`. `s.frobnicate()` can only take an argument of type `ScannerPromise.Result`; you want to pass an argument of arbitrary type `T` and have an existing instance conforming to `Scanner` retroactively change the type of `ScannerPromise.Result`?</div></div></div></div></div></blockquote></div><br></div></div><div>Yes, but I may want ScannerPromise.Result to be a generic parameter. I refer you to my original email:</div><div><br></div><div><span><div></div><div>Even with SE-0142, this kind of constraint would not be possible. What I would like to write is something like this:</div><div><br></div></span><div><span><div><font face="Courier">protocol Promise {</font></div><div><font face="Courier">    associatedtype Result</font></div><div><font face="Courier">    func await() -&gt; Result</font></div><div><font face="Courier">}</font></div><div><font face="Courier"><br></font></div><div><font face="Courier">protocol Scanner {</font></div></span><div><font face="Courier">    associatedtype ScanPromise&lt;X&gt;: Promise where Result == X // (incl. </font><span style="font-family:Courier">SE-0142)</span></div><div><font face="Courier"><br></font></div><div><font face="Courier">    func promiseScan&lt;T&gt;(from: Offset, until: @escaping (Offset, Item) -&gt; T?) -&gt; ScanPromise&lt;T?&gt;</font></div><div><font face="Courier">}</font></div></div><div><div><font face="Courier"><br></font></div><div>So, for example, I could write something like this (allowing my asynchronous Scanners to all automatically implement a synchronous API):</div><div><font face="Courier"><br></font></div><div><font face="Courier">extension Scanner {</font></div><div><font face="Courier">    func scan(from f: Offset, until u: (Offset, Item) -&gt; T?) -&gt; T? {</font></div><div><font face="Courier">        return promiseScan(from: f, until: u).await()</font></div><div><font face="Courier">    }</font></div><div><font face="Courier">}</font></div></div></div><div><br></div><div>A conforming Promise would look like this:</div><div><br></div><div><font face="Courier">class MyPromise&lt;Result&gt;: Promise {</font></div><div><font face="Courier">    func await() -&gt; Result { … }</font></div><div><font face="Courier">}</font></div><div><br></div><div>And a conforming scanner would look like this:</div><div><br></div><div><font face="Courier">class Scanner {</font></div><div><font face="Courier">    typealias ScanPromise&lt;X&gt; = MyPromise&lt;X&gt; // compiler checks where clause: Result == X</font></div><div><font face="Courier"><br></font></div><div><font face="Courier">    public func promiseScan&lt;T&gt;(from f: Offset, until u: @escaping (Offset, Item) -&gt; T?) -&gt; MyPromise&lt;T?&gt; {</font></div><div><font face="Courier">       return MyPromise(from: f, until: u)</font></div><div><font face="Courier">    }</font></div><div><font face="Courier">}</font></div></div></blockquote><div><br></div></div></div><div>I see. Makes sense now. I&#39;m out of my depth here, but that does sound like what you want here is higher kinded types.</div><div><br></div></div></div></div>
<br></div></div><span class="">______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br>
<br></span></blockquote></div><br></div>
</div><br></div>