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

Problems with immutable.Set#++

1 reply
Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 4 days ago.
scala> Set(1, 2) ++ List(2, 3)  // This works fine
res0: scala.collection.immutable.Set[Int] = Set(1, 2, 3)

scala> (Set(1, 2): Set[Any]) ++ List(2, 3) // This blows up
<console>:5: error: ambiguous reference to overloaded definition,
both method ++ in trait Addable of type (elems: Traversable[Any])scala.collection.immutable.Set[Any]
and  method ++ in trait TraversableTemplate of type [B >: Any,That](that: Traversable[B])(implicit bf: scala.collection.generic.BuilderFactory[B,That,scala.collection.immutable.Set[Any]])That
match argument types (List[I...
       (Set(1, 2): Set[Any]) ++ (List(2, 3))
                             ^

Oops...

Worst thing is, I have no idea why one works but the other doesn't.

--j
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Problems with immutable.Set#++

On Mon, Jun 22, 2009 at 01:59:45PM -0700, Jorge Ortiz wrote:
> scala> Set(1, 2) ++ List(2, 3) // This works fine
> res0: scala.collection.immutable.Set[Int] = Set(1, 2, 3)
>
> scala> (Set(1, 2): Set[Any]) ++ List(2, 3) // This blows up
> :5: error: ambiguous reference to overloaded definition,

Late to the party, bub!

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