<div dir="ltr">+1 on HKTs. By the way, there were a couple of people discussing the same here (<a href="https://github.com/typelift/swift/issues/1">https://github.com/typelift/swift/issues/1</a>); you may or may not want to swap ideas with them and see if you can work together towards a formal proposal. (However, since it doesn&#39;t seem HKTs are in scope for Swift 3, a proposal might be deferred until next year.)<div><br></div><div>Austin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 16, 2015 at 9:08 AM, Matthew Johnson 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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>IMO the keys in a dictionary are not part of the contained values and therefore not part of the Functor mapping for Dictionary (obviously a map with different semantics is possible as exhibited by the standard library).  Dictionary should implement Functor by mapping over the values while preserving the keys.</div><div><br></div><div>A similar problem has been noted for Set.  In that case it is not possible to uphold the usual Functor laws.  IMO that points to the need for a protocol with weaker semantics than Functor.  It would preserve the essential structure without preserving the 1 to 1 projection.  There are likely a number of cases where this would make sense.  Functor could inherit from that protocol adding additional semantic requirements but no additional syntactic requirements.</div><div><br></div><div>Matthew<br><br>Sent from my iPad</div><div><div class="h5"><div><br>On Dec 16, 2015, at 8:13 AM, Al Skipp via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div><blockquote type="cite"><div><blockquote style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">let myDictionary: [String:Int] = [&quot;test&quot;: 1]</font></div><div><font face="monospace, monospace">var otherDictionary = myDictionary.myMap { ($0, Float($1)) }</font></div></blockquote><blockquote style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">// does not fail:</font></div></blockquote><blockquote style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">assert(otherDictionary is [String:Float])</font></div></blockquote></div></blockquote></div><br><div>The trouble with Dictionary is that peculiar things can happen if we can map over keys and return a Dictionary.</div><div><br></div><div><div style="margin:0px;font-size:11px;font-family:Menlo"><span style="color:#bb2ca2">let</span> dict = [<span style="color:#d12f1b">&quot;a&quot;</span>:<span style="color:#272ad8">1</span>, <span style="color:#d12f1b">&quot;b&quot;</span>:<span style="color:#272ad8">2</span>, <span style="color:#d12f1b">&quot;c&quot;</span>:<span style="color:#272ad8">3</span>]</div><div style="margin:0px"><span style="font-family:Menlo;font-size:11px;color:rgb(187,44,162)">let</span><font face="Menlo"><span style="font-size:11px"> dict2 = </span></font><span style="font-family:Menlo;font-size:11px;color:rgb(79,129,135)">dict</span><font face="Menlo"><span style="font-size:11px">.</span></font><span style="font-family:Menlo;font-size:11px;color:rgb(61,29,129)">map</span><font face="Menlo"><span style="font-size:11px"> { (</span></font><span style="font-family:Menlo;font-size:11px;color:rgb(209,47,27)">&quot;x&quot;</span><font face="Menlo"><span style="font-size:11px">, $1 * </span></font><span style="font-family:Menlo;font-size:11px;color:rgb(39,42,216)">2</span><font face="Menlo"><span style="font-size:11px">) } // [</span></font><font color="#d12f1b" face="Menlo"><span style="font-size:11px">“x</span></font><font face="Menlo"><font color="#d12f1b"><span style="font-size:11px">”</span></font><span style="font-size:11px">:</span><font color="#272ad8" style="font-size:11px">6]</font></font></div></div><div style="margin:0px;font-size:11px;font-family:Menlo"><br></div><div style="margin:0px">We start with a Dictionary with 3 keys and end up with a Dictionary with 1 key! As the order of the keys is unknown, we have no idea what the value of the key will be either, it might be 6, 4 or 2. </div><div style="margin:0px"><br></div><div style="margin:0px">Swift currently avoids this bedlam by returning an Array of tuples when ‘mapping’ a Dictionary. Strictly speaking this isn’t ‘map’ in the Functor sense, but then again Dictionary is a rogue that refuses to obey the Functor laws anyway.</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAeA9rMnCwt8-2BD7aJoG30t0TCpF3dbIIYy3JwaR542uc1yLyzVVqSLir-2B0-2BymFOdZJghTExNSTFoOm2AeQ411DuFk4DUQ878Ot8xUeupQMnuHiQwzJmINnc62LukksPN4Qd4Oig5PbHfhZ-2F8trdqpKeHhBbOpVeu2Nz-2BKea4AusoPaf8H3tbaF-2FJprmNknuPr-2Bw-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">

</div></blockquote></div></div><blockquote type="cite"><div><span>_______________________________________________</span><span class=""><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></span></div></blockquote>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=7XtDdMHRjqIUi4tzSjSp2pWQIyxYdP6woIWn4vwV5gdIJGWCwfcUDsTDqUnu5Fq6BWg-2F7nS4ziUnY1-2FAcJdRJwiONKNp52NcPHTWVpcD08DVFPhus2nrq7bsp2KP-2BeiaJhzsTkDOgQNcJ98MRziJm-2FvqEifwuYg1XuuVCuKRrehKtetp0IWYBFYHbYGk9AsWy-2BDwiiPwnFzGItygE-2ByXRljDdZFWsSYfGwvEpVxi6No-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>