<div dir="ltr"><span><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">Hi List,</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">I&#39;m very new to swift, and feel quite excited about the features provided by swift.</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">when I tried below example in playground (many of them borrowed from swiftz), I find some swift generics looks wired (to me)</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">(1) When use generics in extension, typealias can refer to generics defined elsewhere</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">(2) types cannot be inferred types as it supposed to be</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">(3) No higher minded types, I found some discussion in the old mail thread, will HKT be part of future swift?</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">// code snippet (using swift 2.2)</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="font-variant-ligatures: no-common-ligatures">public</span><span style="color:#000000"> </span><span style="font-variant-ligatures: no-common-ligatures">struct</span><span style="color:#000000"> K0 {}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="font-variant-ligatures: no-common-ligatures">public</span><span style="color:#000000"> </span><span style="font-variant-ligatures: no-common-ligatures">struct</span><span style="color:#000000"> K1&lt;A&gt; {}</span></p>
<p 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></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="font-variant-ligatures: no-common-ligatures">public</span><span style="color:#000000"> </span><span style="font-variant-ligatures: no-common-ligatures">protocol</span><span style="color:#000000"> Functor{</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:#000000">    </span><span style="font-variant-ligatures: no-common-ligatures">associatedtype</span><span style="color:#000000"> A</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:#000000">    </span><span style="font-variant-ligatures: no-common-ligatures">associatedtype</span><span style="color:#000000"> B</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">    </span><span style="color:#bb2ca2">associatedtype</span><span style="font-variant-ligatures: no-common-ligatures"> FA = K1&lt;A&gt;</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">    </span><span style="color:#bb2ca2">associatedtype</span><span style="font-variant-ligatures: no-common-ligatures"> FB = K1&lt;B&gt;</span></p>
<p 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></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">    </span><span style="color:#bb2ca2">func</span><span style="font-variant-ligatures: no-common-ligatures"> fmap(f : A -&gt; B, </span><span style="color:#bb2ca2">_</span><span style="font-variant-ligatures: no-common-ligatures"> fa : FA) -&gt; FB</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">}</span></p>
<p 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></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">public</span><span style="font-variant-ligatures: no-common-ligatures"> </span><span style="color:#bb2ca2">enum</span><span style="font-variant-ligatures: no-common-ligatures"> Maybe&lt;E&gt; {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">    </span><span style="color:#bb2ca2">case</span><span style="font-variant-ligatures: no-common-ligatures"> Nothing</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">    </span><span style="color:#bb2ca2">case</span><span style="font-variant-ligatures: no-common-ligatures"> Just(</span><span style="color:#4f8187">E</span><span style="font-variant-ligatures: no-common-ligatures">)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">}</span></p>
<p 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></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:#bb2ca2">extension</span><span style="color:#000000"> </span><span style="font-variant-ligatures: no-common-ligatures">Maybe</span><span style="color:#000000"> : </span><span style="font-variant-ligatures: no-common-ligatures">Functor</span><span style="color:#000000"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:#000000">    </span><span style="font-variant-ligatures: no-common-ligatures">public</span><span style="color:#000000"> </span><span style="font-variant-ligatures: no-common-ligatures">typealias</span><span style="color:#000000"> A = </span><span style="color:#4f8187">E         // &lt;---- (1), where is E come from? In extension Maybe, E isn&#39;t part of any context?</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:#000000">    </span><span style="font-variant-ligatures: no-common-ligatures">public</span><span style="color:#000000"> </span><span style="font-variant-ligatures: no-common-ligatures">typealias</span><span style="color:#000000"> B = </span><span style="color:#703daa">Any</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:#000000">    </span><span style="font-variant-ligatures: no-common-ligatures">public</span><span style="color:#000000"> </span><span style="font-variant-ligatures: no-common-ligatures">typealias</span><span style="color:#000000"> FA = </span><span style="color:#4f8187">Maybe</span><span style="color:#000000">&lt;</span><span style="color:#4f8187">A</span><span style="color:#000000">&gt;</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:#000000">    </span><span style="font-variant-ligatures: no-common-ligatures">public</span><span style="color:#000000"> </span><span style="font-variant-ligatures: no-common-ligatures">typealias</span><span style="color:#000000"> FB = </span><span style="color:#4f8187">Maybe</span><span style="color:#000000">&lt;</span><span style="color:#4f8187">B</span><span style="color:#000000">&gt;</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures: no-common-ligatures"> </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">    </span><span style="color:#bb2ca2">public</span><span style="font-variant-ligatures: no-common-ligatures"> </span><span style="color:#bb2ca2">func</span><span style="font-variant-ligatures: no-common-ligatures"> fmap&lt;B&gt; (f : </span><span style="color:#4f8187">A</span><span style="font-variant-ligatures: no-common-ligatures"> -&gt; </span><span style="color:#4f8187">B</span><span style="font-variant-ligatures: no-common-ligatures">, </span><span style="color:#bb2ca2">_</span><span style="font-variant-ligatures: no-common-ligatures"> fa: </span><span style="color:#4f8187">FA</span><span style="font-variant-ligatures: no-common-ligatures">) -&gt; </span><span style="color:#4f8187">Maybe</span><span style="font-variant-ligatures: no-common-ligatures">&lt;</span><span style="color:#4f8187">B</span><span style="font-variant-ligatures: no-common-ligatures">&gt; {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">        </span><span style="color:#bb2ca2">switch</span><span style="font-variant-ligatures: no-common-ligatures">(fa) {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">        </span><span style="color:#bb2ca2">case</span><span style="font-variant-ligatures: no-common-ligatures"> .</span><span style="color:#31595d">Nothing</span><span style="font-variant-ligatures: no-common-ligatures">:</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">            </span><span style="color:#bb2ca2">return</span><span style="font-variant-ligatures: no-common-ligatures"> .</span><span style="color:#31595d">Nothing</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">        </span><span style="color:#bb2ca2">case</span><span style="font-variant-ligatures: no-common-ligatures"> </span><span style="color:#bb2ca2">let</span><span style="font-variant-ligatures: no-common-ligatures"> (.</span><span style="color:#31595d">Just</span><span style="font-variant-ligatures: no-common-ligatures">(a)):</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">            </span><span style="color:#bb2ca2">return</span><span style="font-variant-ligatures: no-common-ligatures"> .</span><span style="color:#31595d">Just</span><span style="font-variant-ligatures: no-common-ligatures">(f(a))</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">        }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">}</span></p>
<p 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></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">public</span><span style="font-variant-ligatures: no-common-ligatures"> </span><span style="color:#bb2ca2">func</span><span style="font-variant-ligatures: no-common-ligatures"> fmap&lt;A, B&gt; (f : </span><span style="color:#4f8187">A</span><span style="font-variant-ligatures: no-common-ligatures"> -&gt; </span><span style="color:#4f8187">B</span><span style="font-variant-ligatures: no-common-ligatures">, </span><span style="color:#bb2ca2">_</span><span style="font-variant-ligatures: no-common-ligatures"> fa : </span><span style="color:#4f8187">Maybe</span><span style="font-variant-ligatures: no-common-ligatures">&lt;</span><span style="color:#4f8187">A</span><span style="font-variant-ligatures: no-common-ligatures">&gt;) -&gt; </span><span style="color:#4f8187">Maybe</span><span style="font-variant-ligatures: no-common-ligatures">&lt;</span><span style="color:#4f8187">B</span><span style="font-variant-ligatures: no-common-ligatures">&gt; {       // &lt;----- lack of Higher minded type, thus every extension implements protocol ``Functor`` need this boilerplate?</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">    </span><span style="color:#bb2ca2">return</span><span style="font-variant-ligatures: no-common-ligatures"> fa.</span><span style="color:#31595d">fmap</span><span style="font-variant-ligatures: no-common-ligatures">(f, fa)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">}</span></p>
<p 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></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">func</span><span style="font-variant-ligatures: no-common-ligatures"> succ (x : </span><span style="color:#703daa">Int</span><span style="font-variant-ligatures: no-common-ligatures">) -&gt; </span><span style="color:#703daa">Int</span><span style="font-variant-ligatures: no-common-ligatures"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">    </span><span style="color:#bb2ca2">return</span><span style="font-variant-ligatures: no-common-ligatures"> </span><span style="color:#272ad8">1</span><span style="font-variant-ligatures: no-common-ligatures"> + x</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures: no-common-ligatures">}</span></p>
<p 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></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">let x0 = .Nothing          // &lt;------- type error, cannot infer x0</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">let</span><span style="font-variant-ligatures: no-common-ligatures"> x1 = .Just(</span><span style="color:#272ad8">1</span><span style="font-variant-ligatures: no-common-ligatures">)          // &lt;------- type error, cannot infer x1, which is (Maybe Int)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">let</span><span style="font-variant-ligatures: no-common-ligatures"> x2 : </span><span style="color:#4f8187">Maybe</span><span style="font-variant-ligatures: no-common-ligatures">&lt;</span><span style="color:#703daa">Int</span><span style="font-variant-ligatures: no-common-ligatures">&gt; = .</span><span style="color:#31595d">Just</span><span style="font-variant-ligatures: no-common-ligatures">(</span><span style="color:#272ad8">1</span><span style="font-variant-ligatures: no-common-ligatures">)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">let</span><span style="font-variant-ligatures: no-common-ligatures"> x3 = </span><span style="color:#31595d">fmap</span><span style="font-variant-ligatures: no-common-ligatures">(</span><span style="color:#31595d">succ</span><span style="font-variant-ligatures: no-common-ligatures">, </span><span style="color:#4f8187">x2</span><span style="font-variant-ligatures: no-common-ligatures">)</span></p></span><div><br></div><div><br></div>Thanks<div>baojun<br><div><br></div></div></div>