ScalaのmutableのHashSetの面白い挙動
scala> val a = BigDecimal(42) a: scala.math.BigDecimal = 42 scala> a == a.toDouble res0: Boolean = true scala> List(a, a.toDouble).distinct res1: List[Any] = List(42, 42.0)
2017-12-30 00:55:02@xuwei_k scala> List(a.toDouble.asInstanceOf[Any] , a.asInstanceOf[Any]).toSet res2: scala.collection.immutable.Set[Any] = Set(42.0) scala> List(a.toDouble.asInstanceOf[Any] , a.asInstanceOf[Any]).distinct res3: List[Any] = List(42.0, 42)
2017-12-30 01:40:23@xuwei_k set aside the universal equality, the culprit here is lub on List.apply[A](...). I hope we will have a way to check for all lubbing in 2018.
2018-01-02 09:02:31@eed3si9n @xuwei_k your resource on that topic: eed3si9n.com/stricter-scala…
2018-01-02 11:49:39@eed3si9n @xuwei_k I don't understand. How are they distinct if they are == each other? Shouldn't it still be using scala.math.BigDecimal#==?
2018-01-02 23:10:42@dwijnand @eed3si9n scala> val a = BigDecimal(42) a: scala.math.BigDecimal = 42 scala> val b = a.toDouble b: Double = 42.0 scala> a.## res0: Int = 42 scala> b.## res1: Int = 42 scala> a.hashCode res2: Int = 42 scala> b.hashCode res3: Int = 1078263808
2018-01-03 00:03:32@dwijnand List#distinct use mutable.HashSet mutable.HashSet use FlatHashTable FlatHashTable use hashCode ( not ## ) github.com/scala/scala/bl… github.com/scala/scala/bl… github.com/scala/scala/bl…
2018-01-03 00:08:00scala> val a = BigDecimal(7) a: scala.math.BigDecimal = 7 scala> val b = a.toDouble b: Double = 7.0 scala> collection.mutable.Set(a,b) res0: scala.collection.mutable.Set[Any] = Set(7, 7.0) scala> collection.immutable.Set(a,b) res1: scala.collection.immutable.Set[Any] = Set(7)
2018-01-03 00:10:23@eed3si9n @xuwei_k could you explain why the result is false for #1? @ List(x, x.toDouble).distinct res5: List[Any] = List(42, 42.0) @ Set(x, x.toDouble) res7: Set[Any] = Set(42) @ (x: Any) == (x.toDouble: Any) res13: Boolean = true thanks!
2018-01-03 00:11:42