<div dir="ltr">The implementation of set-union for hash sets would be unnecessarily slow if that&#39;s how I wrote it.  It&#39;s faster to extract the hash tables and operate directly on those.  It&#39;s even faster still to find the largest immutable hash table in the argument list and start from that.  On top of that, the operation is specified, since before my changes, to go through the arguments and reject any hash sets that use a different notion of equality, so that the output of set-union has a meaningful semantics.  For an arbitrary other set representation, I don&#39;t necessarily know what the notion of equality is.  So currently, I just reject all of them.<br>

</div><div class="gmail_extra"><br clear="all"><div>Carl Eastlund</div>
<br><br><div class="gmail_quote">On Thu, Aug 22, 2013 at 1:52 PM, Jay McCarthy <span dir="ltr">&lt;<a href="mailto:jay.mccarthy@gmail.com" target="_blank">jay.mccarthy@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

I find this an unsatisfying consequence of the implementation and not<br>
necessary. For instance, you could implement set-union purely<br>
generically as:<br>
<br>
(define (set-union a b)<br>
 (for/fold ([a a]) ([e (in-set b)]) (set-add a e)))<br>
<br>
and then it would work for everything. Right?<br>
<br>
Jay<br>
<div class="HOEnZb"><div class="h5"><br>
On Thu, Aug 22, 2013 at 10:14 AM, Carl Eastlund &lt;<a href="mailto:cce@ccs.neu.edu">cce@ccs.neu.edu</a>&gt; wrote:<br>
&gt; Set-union never worked for even different hash set representations.  Even<br>
&gt; before I touched the code, the union of an eq set and an eqv set, for<br>
&gt; instance, caused a runtime error.<br>
&gt;<br>
&gt; Generics do not have multiple dispatch.  That&#39;s not a mechanism we have<br>
&gt; right now.  And &quot;fallbacks&quot; are for when there&#39;s no method implemented for a<br>
&gt; given receiver value, they&#39;re not particularly related to a question of &quot;are<br>
&gt; these things the same type&quot;.<br>
&gt;<br>
&gt; I chose to keep the semantics that union and operations like it only work<br>
&gt; with the same representation.  Partly because that&#39;s how things already<br>
&gt; were, and partly to set the precedent that generics authors don&#39;t have to<br>
&gt; write two versions of every method.  Perhaps this wasn&#39;t the best idiom, but<br>
&gt; it&#39;s what I wrote.  Perhaps there&#39;s a better idiom for fallbacks that makes<br>
&gt; this work more cleanly.  Anyway, right now, generic sets are designed so you<br>
&gt; can use any one representation, but they don&#39;t combine representations.<br>
&gt;<br>
&gt; Carl Eastlund<br>
&gt;<br>
&gt;<br>
&gt; On Thu, Aug 22, 2013 at 9:03 AM, J. Ian Johnson &lt;<a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; No, it doesn&#39;t seem to be using the fallback in this case.<br>
&gt;&gt;<br>
&gt;&gt; ianj@sampson:~/racket/racket/bin$ ./racket -il xrepl<br>
&gt;&gt; Welcome to Racket v5.90.0.8.<br>
&gt;&gt; -&gt; (set-union &#39;() (set))<br>
&gt;&gt; ; in-list: contract violation<br>
&gt;&gt; ;   expected: list?<br>
&gt;&gt; ;   given: (set)<br>
&gt;&gt; ; [,bt for context]<br>
&gt;&gt; -&gt;<br>
&gt;&gt;<br>
&gt;&gt; -Ian<br>
&gt;&gt; ----- Original Message -----<br>
&gt;&gt; From: &quot;Sam Tobin-Hochstadt&quot; &lt;<a href="mailto:samth@cs.indiana.edu">samth@cs.indiana.edu</a>&gt;<br>
&gt;&gt; To: &quot;J. Ian Johnson&quot; &lt;<a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a>&gt;, &quot;Carl Eastlund&quot; &lt;<a href="mailto:cce@ccs.neu.edu">cce@ccs.neu.edu</a>&gt;<br>
&gt;&gt; Cc: <a href="mailto:dev@racket-lang.org">dev@racket-lang.org</a>, &quot;Matthew Flatt&quot; &lt;<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>&gt;<br>
&gt;&gt; Sent: Thursday, August 22, 2013 8:51:30 AM GMT -05:00 US/Canada Eastern<br>
&gt;&gt; Subject: Re: [racket-dev] Lists aren&#39;t sets, but have set-like operations<br>
&gt;&gt;<br>
&gt;&gt; Wait, `set-union` of two different set representations doesn&#39;t work?<br>
&gt;&gt;<br>
&gt;&gt; Sam<br>
&gt;&gt;<br>
&gt;&gt; On Thu, Aug 22, 2013 at 8:07 AM, J. Ian Johnson &lt;<a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a>&gt; wrote:<br>
&gt;&gt; &gt; You misunderstand. I used set-union, but single dispatch saw &#39;() and<br>
&gt;&gt; &gt; used list-union for the &#39;() (set) combination.<br>
&gt;&gt; &gt; -Ian<br>
&gt;&gt; &gt; ----- Original Message -----<br>
&gt;&gt; &gt; From: &quot;Sam Tobin-Hochstadt&quot; &lt;<a href="mailto:samth@cs.indiana.edu">samth@cs.indiana.edu</a>&gt;<br>
&gt;&gt; &gt; To: &quot;J. Ian Johnson&quot; &lt;<a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a>&gt;<br>
&gt;&gt; &gt; Cc: <a href="mailto:dev@racket-lang.org">dev@racket-lang.org</a>, &quot;Matthew Flatt&quot; &lt;<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>&gt;<br>
&gt;&gt; &gt; Sent: Thursday, August 22, 2013 8:02:50 AM GMT -05:00 US/Canada Eastern<br>
&gt;&gt; &gt; Subject: Re: [racket-dev] Lists aren&#39;t sets, but have set-like<br>
&gt;&gt; &gt; operations<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; But &#39;list-union&#39; is not a generic operation so it isn&#39;t surprising that<br>
&gt;&gt; &gt; this didn&#39;t work. To do this generically, you&#39;d need to use &#39;set-union&#39;.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Sam<br>
&gt;&gt; &gt; On Aug 22, 2013 7:59 AM, &quot;J. Ian Johnson&quot; &lt; <a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a> &gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; The problem manifested itself when I got an exception that in-list can&#39;t<br>
&gt;&gt; &gt; be called on (set), which really confused me. (set? &#39;()) answered true, so<br>
&gt;&gt; &gt; it tried to do (list-union &#39;() (set)), which failed.<br>
&gt;&gt; &gt; Generic sets as they are don&#39;t work generically. Some action should be<br>
&gt;&gt; &gt; taken. Either set? means what it once did, or we do some awfully slow<br>
&gt;&gt; &gt; multiple dispatch for set operations. My bias shows.<br>
&gt;&gt; &gt; -Ian<br>
&gt;&gt; &gt; ----- Original Message -----<br>
&gt;&gt; &gt; From: &quot;Matthew Flatt&quot; &lt; <a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a> &gt;<br>
&gt;&gt; &gt; To: &quot;Carl Eastlund&quot; &lt; <a href="mailto:cce@ccs.neu.edu">cce@ccs.neu.edu</a> &gt;<br>
&gt;&gt; &gt; Cc: &quot;J. Ian Johnson&quot; &lt; <a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a> &gt;, &quot;dev&quot; &lt; <a href="mailto:dev@racket-lang.org">dev@racket-lang.org</a> &gt;<br>
&gt;&gt; &gt; Sent: Thursday, August 22, 2013 7:22:25 AM GMT -05:00 US/Canada Eastern<br>
&gt;&gt; &gt; Subject: Re: [racket-dev] Lists aren&#39;t sets, but have set-like<br>
&gt;&gt; &gt; operations<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; How much should we prioritize backward compatibility in this case?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; One possibility is to make `set?&#39; mean `hash-set?&#39;, and add<br>
&gt;&gt; &gt; `generic-set?&#39; in place of the current `set?&#39;. That&#39;s uglier,<br>
&gt;&gt; &gt; obviously, but it would be better if we want to prioritize backward<br>
&gt;&gt; &gt; compatibility.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; At Wed, 21 Aug 2013 19:14:06 -0400, Carl Eastlund wrote:<br>
&gt;&gt; &gt;&gt; Ah, yes. The set? predicate no longer distinguishes a representation.<br>
&gt;&gt; &gt;&gt; There are several predicates for the original set type, now called<br>
&gt;&gt; &gt;&gt; &quot;hash<br>
&gt;&gt; &gt;&gt; sets&quot;: set-eq?, set-eqv?, set-equal?, set-mutable?, set-immtuable?, and<br>
&gt;&gt; &gt;&gt; set-weak?. I didn&#39;t add the basic &quot;hash-set?&quot;, but perhaps I should.<br>
&gt;&gt; &gt;&gt; It&#39;s<br>
&gt;&gt; &gt;&gt; a weird name, since &quot;hash-set&quot; and &quot;hash-set!&quot; are already existing,<br>
&gt;&gt; &gt;&gt; unrelated functions.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Carl Eastlund<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; On Wed, Aug 21, 2013 at 7:08 PM, J. Ian Johnson &lt; <a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a> &gt;<br>
&gt;&gt; &gt;&gt; wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt; Okay, I can abide. However, that doesn&#39;t really get at my<br>
&gt;&gt; &gt;&gt; &gt; frustration. I&#39;m<br>
&gt;&gt; &gt;&gt; &gt; using the set constructor, that appears to now be an<br>
&gt;&gt; &gt;&gt; &gt; immutable-custom-set<br>
&gt;&gt; &gt;&gt; &gt; with make-immutable-hash as its make-table. So what I&#39;m looking for<br>
&gt;&gt; &gt;&gt; &gt; is not<br>
&gt;&gt; &gt;&gt; &gt; set?, but set-immutable?, as it&#39;s a distinct (family of) struct types<br>
&gt;&gt; &gt;&gt; &gt; that<br>
&gt;&gt; &gt;&gt; &gt; won&#39;t clash with the primitive data that I&#39;m otherwise using.<br>
&gt;&gt; &gt;&gt; &gt; -Ian<br>
&gt;&gt; &gt;&gt; &gt; ----- Original Message -----<br>
&gt;&gt; &gt;&gt; &gt; From: &quot;Carl Eastlund&quot; &lt; <a href="mailto:cce@ccs.neu.edu">cce@ccs.neu.edu</a> &gt;<br>
&gt;&gt; &gt;&gt; &gt; To: &quot;J. Ian Johnson&quot; &lt; <a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a> &gt;<br>
&gt;&gt; &gt;&gt; &gt; Cc: &quot;dev&quot; &lt; <a href="mailto:dev@racket-lang.org">dev@racket-lang.org</a> &gt;<br>
&gt;&gt; &gt;&gt; &gt; Sent: Wednesday, August 21, 2013 6:58:56 PM GMT -05:00 US/Canada<br>
&gt;&gt; &gt;&gt; &gt; Eastern<br>
&gt;&gt; &gt;&gt; &gt; Subject: Re: [racket-dev] Lists aren&#39;t sets, but have set-like<br>
&gt;&gt; &gt;&gt; &gt; operations<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Ian, sets are now a generic datatype, like dictionaries. Association<br>
&gt;&gt; &gt;&gt; &gt; lists<br>
&gt;&gt; &gt;&gt; &gt; are dictionaries, and lists are now sets. They&#39;re also streams and<br>
&gt;&gt; &gt;&gt; &gt; sequences. They&#39;re not just &quot;set-like&quot;.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Carl Eastlund<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; On Wed, Aug 21, 2013 at 6:56 PM, J. Ian Johnson &lt; <a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a> &gt;<br>
&gt;&gt; &gt;&gt; &gt; wrote:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; I just wasted about 2 hours tracking down a bug that ended up being<br>
&gt;&gt; &gt;&gt; &gt; due to<br>
&gt;&gt; &gt;&gt; &gt; (set? &#39;()) now evaluating to #t. I have no problems with set-union,<br>
&gt;&gt; &gt;&gt; &gt; intersection, etc. being defined for lists, but to treat lists as<br>
&gt;&gt; &gt;&gt; &gt; sets<br>
&gt;&gt; &gt;&gt; &gt; always is perverse to me. The contracts for set operations should use<br>
&gt;&gt; &gt;&gt; &gt; set-like? for (or/c set? list?) and keep the two constructions<br>
&gt;&gt; &gt;&gt; &gt; separate.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; This conflation is almost as bad as treating empty list as false.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; -Ian<br>
&gt;&gt; &gt;&gt; &gt; _________________________<br>
&gt;&gt; &gt;&gt; &gt; Racket Developers list:<br>
&gt;&gt; &gt;&gt; &gt; <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; _________________________<br>
&gt;&gt; &gt;&gt; Racket Developers list:<br>
&gt;&gt; &gt;&gt; <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
&gt;&gt; &gt; _________________________<br>
&gt;&gt; &gt; Racket Developers list:<br>
&gt;&gt; &gt; <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt; _________________________<br>
&gt;   Racket Developers list:<br>
&gt;   <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
&gt;<br>
<br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Jay McCarthy &lt;<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>&gt;<br>
Assistant Professor / Brigham Young University<br>
<a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
<br>
&quot;The glory of God is Intelligence&quot; - D&amp;C 93<br>
<br>
</font></span></blockquote></div><br></div>