This page is no longer maintained — Please continue to the home page at www.scala-lang.org

array equality

1 reply
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.

One of the more interesting incongruities in the new lib:

scala> Array(1) == Array(1)
res0: Boolean = false

scala> Array(1) equals Array(1)
res1: Boolean = true

I haven't track that down, but I'm guessing the first goes straight to
java's equality for arrays and the second uses the equals override in
Iterable or similar. I see comments to the effect that array equality
semantics still needs to be decided. What are we thinking these days?

Maybe there's still time to do something about arrays for 2.8 - they
have quite a disproportionate standing in the bug database.

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: array equality

On Sat, May 9, 2009 at 2:49 PM, Paul Phillips wrote:
> One of the more interesting incongruities in the new lib:
>
> scala> Array(1) == Array(1)
> res0: Boolean = false
>
> scala> Array(1) equals Array(1)
> res1: Boolean = true
>
> I haven't track that down, but I'm guessing the first goes straight to
> java's equality for arrays and the second uses the equals override in
> Iterable or similar.  I see comments to the effect that array equality
> semantics still needs to be decided.  What are we thinking these days?
>
> Maybe there's still time to do something about arrays for 2.8 - they
> have quite a disproportionate standing in the bug database.
>
Yes, that's on the todo list. The intention is that Array(1) ==
Array(1) should return true. Something in erasure needs to be twiddled
to make that happen, I guess.
I am planning to have a look at this soon.

Cheers

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland