<div dir="ltr"><div><div><div>I think it is a good idea to let multiple kinds of sets interact, but at the time I implemented all this I wasn&#39;t sure exactly how to make it work, so I took a conservative approach -- make it an error now; then we can make it a non-error later any way we want, without constraint.  I don&#39;t want to give the impression I&#39;m against interoperation.<br>

<br></div>Here&#39;s what I propose to do now:<br><br></div>- rename set? to generic-set?; this predicate recognizes the new all-inclusive generic set type<br></div><div>- rename set-immutable? to set?; this predicate recognizes the pre-existing immutable hash set type<br>

</div><div>- leave set-mutable? and set-weak? alone; they recognize the other two hash set types (on the mutability axis)<br></div><div>- allow multiple-set operations to combine equal-based hash sets and lists, since both use equal? for equality<br>

<br></div><div>I don&#39;t know how to make other user-defined types recognize when they share a notion of equality.  I&#39;m not 100% sure that rejecting these operations when sets don&#39;t share a notion of equality is actually the right thing to do; sometimes it&#39;s best to just let the user take responsibility for whether putting the elements of one set into another will have meaningful results.  But that restriction is documented and predates my changes, so I&#39;m leaving it in unless someone wants to propose a better way.  That means rejecting all other kinds of sets beyond hash sets and lists for union, intersection, etc.<br>

</div><div class="gmail_extra"><br clear="all"><div>Carl Eastlund</div>
<br><div class="gmail_quote">On Thu, Aug 22, 2013 at 12:27 PM, Matthias Felleisen <span dir="ltr">&lt;<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>&gt;</span> wrote:<br><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><br></div><div>I can see why an eq-set and an eqv-set can&#39;t be union-ed without additional information about the desired result type. </div><div><br></div><div>But if we had two different implementation of the eq-set API we could easily define unions as derived code; that&#39;s the point of OO. </div>

<div><div class="h5"><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><br><div><div>On Aug 22, 2013, at 12:14 PM, Carl Eastlund wrote:</div><br><blockquote type="cite"><div dir="ltr"><div><div>Set-union never worked for even different hash set representations.  Even before I touched the code, the union of an eq set and an eqv set, for instance, caused a runtime error.<br>

<br></div>Generics do not have multiple dispatch.  That&#39;s not a mechanism we have right now.  And &quot;fallbacks&quot; are for when there&#39;s no method implemented for a given receiver value, they&#39;re not particularly related to a question of &quot;are these things the same type&quot;.<br>



<br></div>I chose to keep the semantics that union and operations like it only work with the same representation.  Partly because that&#39;s how things already were, and partly to set the precedent that generics authors don&#39;t have to write two versions of every method.  Perhaps this wasn&#39;t the best idiom, but it&#39;s what I wrote.  Perhaps there&#39;s a better idiom for fallbacks that makes this work more cleanly.  Anyway, right now, generic sets are designed so you can use any one representation, but they don&#39;t combine representations.<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 9:03 AM, J. Ian Johnson <span dir="ltr">&lt;<a href="mailto:ianj@ccs.neu.edu" target="_blank">ianj@ccs.neu.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



No, it doesn&#39;t seem to be using the fallback in this case.<br>
<br>
ianj@sampson:~/racket/racket/bin$ ./racket -il xrepl<br>
Welcome to Racket v5.90.0.8.<br>
-&gt; (set-union &#39;() (set))<br>
; in-list: contract violation<br>
;   expected: list?<br>
;   given: (set)<br>
; [,bt for context]<br>
-&gt;<br>
<div><br>
-Ian<br>
----- Original Message -----<br>
From: &quot;Sam Tobin-Hochstadt&quot; &lt;<a href="mailto:samth@cs.indiana.edu" target="_blank">samth@cs.indiana.edu</a>&gt;<br>
</div><div>To: &quot;J. Ian Johnson&quot; &lt;<a href="mailto:ianj@ccs.neu.edu" target="_blank">ianj@ccs.neu.edu</a>&gt;, &quot;Carl Eastlund&quot; &lt;<a href="mailto:cce@ccs.neu.edu" target="_blank">cce@ccs.neu.edu</a>&gt;<br>


Cc: <a href="mailto:dev@racket-lang.org" target="_blank">dev@racket-lang.org</a>, &quot;Matthew Flatt&quot; &lt;<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>&gt;<br>
</div><div><div>Sent: Thursday, August 22, 2013 8:51:30 AM GMT -05:00 US/Canada Eastern<br>
Subject: Re: [racket-dev] Lists aren&#39;t sets, but have set-like operations<br>
<br>
Wait, `set-union` of two different set representations doesn&#39;t work?<br>
<br>
Sam<br>
<br>
On Thu, Aug 22, 2013 at 8:07 AM, J. Ian Johnson &lt;<a href="mailto:ianj@ccs.neu.edu" target="_blank">ianj@ccs.neu.edu</a>&gt; wrote:<br>
&gt; You misunderstand. I used set-union, but single dispatch saw &#39;() and used list-union for the &#39;() (set) combination.<br>
&gt; -Ian<br>
&gt; ----- Original Message -----<br>
&gt; From: &quot;Sam Tobin-Hochstadt&quot; &lt;<a href="mailto:samth@cs.indiana.edu" target="_blank">samth@cs.indiana.edu</a>&gt;<br>
&gt; To: &quot;J. Ian Johnson&quot; &lt;<a href="mailto:ianj@ccs.neu.edu" target="_blank">ianj@ccs.neu.edu</a>&gt;<br>
&gt; Cc: <a href="mailto:dev@racket-lang.org" target="_blank">dev@racket-lang.org</a>, &quot;Matthew Flatt&quot; &lt;<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>&gt;<br>
&gt; Sent: Thursday, August 22, 2013 8:02:50 AM GMT -05:00 US/Canada Eastern<br>
&gt; Subject: Re: [racket-dev] Lists aren&#39;t sets, but have set-like operations<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; But &#39;list-union&#39; is not a generic operation so it isn&#39;t surprising that this didn&#39;t work. To do this generically, you&#39;d need to use &#39;set-union&#39;.<br>
&gt;<br>
&gt; Sam<br>
&gt; On Aug 22, 2013 7:59 AM, &quot;J. Ian Johnson&quot; &lt; <a href="mailto:ianj@ccs.neu.edu" target="_blank">ianj@ccs.neu.edu</a> &gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt; The problem manifested itself when I got an exception that in-list can&#39;t be called on (set), which really confused me. (set? &#39;()) answered true, so it tried to do (list-union &#39;() (set)), which failed.<br>




&gt; Generic sets as they are don&#39;t work generically. Some action should be taken. Either set? means what it once did, or we do some awfully slow multiple dispatch for set operations. My bias shows.<br>
&gt; -Ian<br>
&gt; ----- Original Message -----<br>
&gt; From: &quot;Matthew Flatt&quot; &lt; <a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a> &gt;<br>
&gt; To: &quot;Carl Eastlund&quot; &lt; <a href="mailto:cce@ccs.neu.edu" target="_blank">cce@ccs.neu.edu</a> &gt;<br>
&gt; Cc: &quot;J. Ian Johnson&quot; &lt; <a href="mailto:ianj@ccs.neu.edu" target="_blank">ianj@ccs.neu.edu</a> &gt;, &quot;dev&quot; &lt; <a href="mailto:dev@racket-lang.org" target="_blank">dev@racket-lang.org</a> &gt;<br>


&gt; Sent: Thursday, August 22, 2013 7:22:25 AM GMT -05:00 US/Canada Eastern<br>
&gt; Subject: Re: [racket-dev] Lists aren&#39;t sets, but have set-like operations<br>
&gt;<br>
&gt; How much should we prioritize backward compatibility in this case?<br>
&gt;<br>
&gt; One possibility is to make `set?&#39; mean `hash-set?&#39;, and add<br>
&gt; `generic-set?&#39; in place of the current `set?&#39;. That&#39;s uglier,<br>
&gt; obviously, but it would be better if we want to prioritize backward<br>
&gt; compatibility.<br>
&gt;<br>
&gt; At Wed, 21 Aug 2013 19:14:06 -0400, Carl Eastlund wrote:<br>
&gt;&gt; Ah, yes. The set? predicate no longer distinguishes a representation.<br>
&gt;&gt; There are several predicates for the original set type, now called &quot;hash<br>
&gt;&gt; sets&quot;: set-eq?, set-eqv?, set-equal?, set-mutable?, set-immtuable?, and<br>
&gt;&gt; set-weak?. I didn&#39;t add the basic &quot;hash-set?&quot;, but perhaps I should. It&#39;s<br>
&gt;&gt; a weird name, since &quot;hash-set&quot; and &quot;hash-set!&quot; are already existing,<br>
&gt;&gt; unrelated functions.<br>
&gt;&gt;<br>
&gt;&gt; Carl Eastlund<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Wed, Aug 21, 2013 at 7:08 PM, J. Ian Johnson &lt; <a href="mailto:ianj@ccs.neu.edu" target="_blank">ianj@ccs.neu.edu</a> &gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; &gt; Okay, I can abide. However, that doesn&#39;t really get at my frustration. I&#39;m<br>
&gt;&gt; &gt; using the set constructor, that appears to now be an immutable-custom-set<br>
&gt;&gt; &gt; with make-immutable-hash as its make-table. So what I&#39;m looking for is not<br>
&gt;&gt; &gt; set?, but set-immutable?, as it&#39;s a distinct (family of) struct types that<br>
&gt;&gt; &gt; won&#39;t clash with the primitive data that I&#39;m otherwise using.<br>
&gt;&gt; &gt; -Ian<br>
&gt;&gt; &gt; ----- Original Message -----<br>
&gt;&gt; &gt; From: &quot;Carl Eastlund&quot; &lt; <a href="mailto:cce@ccs.neu.edu" target="_blank">cce@ccs.neu.edu</a> &gt;<br>
&gt;&gt; &gt; To: &quot;J. Ian Johnson&quot; &lt; <a href="mailto:ianj@ccs.neu.edu" target="_blank">ianj@ccs.neu.edu</a> &gt;<br>
&gt;&gt; &gt; Cc: &quot;dev&quot; &lt; <a href="mailto:dev@racket-lang.org" target="_blank">dev@racket-lang.org</a> &gt;<br>
&gt;&gt; &gt; Sent: Wednesday, August 21, 2013 6:58:56 PM GMT -05:00 US/Canada Eastern<br>
&gt;&gt; &gt; Subject: Re: [racket-dev] Lists aren&#39;t sets, but have set-like operations<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Ian, sets are now a generic datatype, like dictionaries. Association lists<br>
&gt;&gt; &gt; are dictionaries, and lists are now sets. They&#39;re also streams and<br>
&gt;&gt; &gt; sequences. They&#39;re not just &quot;set-like&quot;.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Carl Eastlund<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Wed, Aug 21, 2013 at 6:56 PM, J. Ian Johnson &lt; <a href="mailto:ianj@ccs.neu.edu" target="_blank">ianj@ccs.neu.edu</a> &gt;<br>
&gt;&gt; &gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I just wasted about 2 hours tracking down a bug that ended up being due to<br>
&gt;&gt; &gt; (set? &#39;()) now evaluating to #t. I have no problems with set-union,<br>
&gt;&gt; &gt; intersection, etc. being defined for lists, but to treat lists as sets<br>
&gt;&gt; &gt; always is perverse to me. The contracts for set operations should use<br>
&gt;&gt; &gt; set-like? for (or/c set? list?) and keep the two constructions separate.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; This conflation is almost as bad as treating empty list as false.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; -Ian<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; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; _________________________<br>
&gt;&gt; Racket Developers list:<br>
&gt;&gt; <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><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>
<br>
</div></div></blockquote></div><br></div>
_________________________<br>  Racket Developers list:<br>  <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br></blockquote></div><br></div></div></div></blockquote></div><br>

</div></div>