In article <slrnch59s7.77a.csaba / degas.ceu.hu>, Csaba Henk wrote:
> require 'set'
> #the empty set:
> Set[]
> => #<Set: {}>
> #the singleton of the empty set:
> Set[ [Set[]] ]
> => #<Set: {[#<Set: {}>]}>
> #if sets were extensional as God ordered, this would give the same, but...
> Set[ [Set[], Set[]] ] 
> => #<Set: {[#<Set: {}>, #<Set: {}>]}>
> #and also...
> Set[Set[]].member? Set[]
> => false
> [Set[], Set[]].uniq
> => [#<Set: {}>, #<Set: {}>]
> Set[ [Set[]] ] - Set[ [Set[]] ]
> => #<Set: {[#<Set: {}>]}>
> #anyway...
> Set[] == Set[]
> => true
> Set[ [Set[]] ] == Set[ [Set[]] ]
> => false
> 
> (Set.new behaves the same way as Set[])
> 
> Now I don't see what's the purpose of having a set class which is not
> extensional (ie., two sets behave as the same one in all respect if their
> elements are the same). But, given it's non-extensional, why isn't it
> consequently non-extensional ("Set[] == Set[]" evaluates in an extensional
> manner, that is, to "true")? And how does Array#uniq work? -- by what rule
> does it dispose elements if not by getting "true" by a "==" comparison with
> an other member of the array?

I've read the thread spawned by this post, and now I summarize that part of
what was written there which is relevant to my original problem, and wasn't
stated there explicitly.

"Set" can be forced to behave extensionally by doing so:

class Set
  def eql? other
    subset? other and other.subset? self
  end
  def hash
    to_a.hash
  end
end

-- as it seems to me, Array#uniq uses *both* of eql? and hash methods, and
to get rid of the (IMHO pathological) behaviour illustrated by the above
examples, both methods need to be overwritten. Concerning the above
re-implementation of these methods, what I did with "hash" is just a hack, of
course, I don't claim that it clean or right to do so, it just something
which does the job.

-- 
Csaba

"There's more to life, than books, you know but not much more..."
[The Smiths]
***
If you want to send me a mail, see it in the mailto link at
http://www.renyi.hu/~ekho/egyelore.html