- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Why Seq is not scala.collection.immutable.Seq
Thu, 2010-09-23, 21:59
Hi,
Without importing anything, Set refers to scala.collection.immutable.Set and Map to scala.collection.immutable.Map. Why Seq refers to scala.collection.Seq?
Welcome to Scala version 2.8.0.r22899-b20100902020112 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20). Type in expressions to have them evaluated.Type :help for more information.
scala> classOf[Seq[_]]res0: java.lang.Class[Seq[_]] = interface scala.collection.Seq
scala> classOf[Set[_]]res1: java.lang.Class[Set[_]] = interface scala.collection.immutable.Set
scala> classOf[Map[_,_]]res2: java.lang.Class[Map[_, _]] = interface scala.collection.immutable.Map
Regards,Germán
Without importing anything, Set refers to scala.collection.immutable.Set and Map to scala.collection.immutable.Map. Why Seq refers to scala.collection.Seq?
Welcome to Scala version 2.8.0.r22899-b20100902020112 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20). Type in expressions to have them evaluated.Type :help for more information.
scala> classOf[Seq[_]]res0: java.lang.Class[Seq[_]] = interface scala.collection.Seq
scala> classOf[Set[_]]res1: java.lang.Class[Set[_]] = interface scala.collection.immutable.Set
scala> classOf[Map[_,_]]res2: java.lang.Class[Map[_, _]] = interface scala.collection.immutable.Map
Regards,Germán
Thu, 2010-09-23, 23:27
#2
Re: Why Seq is not scala.collection.immutable.Seq
On Thu, Sep 23, 2010 at 6:33 PM, Lex <lexn82@gmail.com> wrote:
This doesn't make sense to me. If I want a mutable Seq I'll use mutable.Seq as I have to do with Map and Set. Is there any documentation about this decision?
Java arrays are wrapped into WrappedArray to integrate with scala collection API. Arrays are used very often and WrappedArray is "mutable.Seq", so it makes sense for "Seq" to be the common supertype "scala.collection.Seq" by default.
This doesn't make sense to me. If I want a mutable Seq I'll use mutable.Seq as I have to do with Map and Set. Is there any documentation about this decision?
Fri, 2010-09-24, 22:07
#3
Re: Why Seq is not scala.collection.immutable.Seq
Hi,
Another (somewhat related) questions.
I've noticed that the default "IndexedSeq" is "collection.IndexedSeq" (like in "Seq") but the type of "toIndexedSeq" is "immutable.IndexedSeq".
Is this an error or is on purpose? maybe "IndexedSeq" should be by default "immutable.IndexedSeq"?
Thinking (erroneously) that "Seq" was by default "immutable.Seq", I was using it as the default type for the seq-like parameters of my methods. Now I'm thinking in change all source files using "Seq" to assure that "immutable.Seq" it's what is in scope.
What type do you use in such cases? "immutable.Seq" or anything else?
Sorry if this has been discussed previously. Any reference to the discussions regarding the default "Seq" and "IndexedSeq" and/or the return type of "toSeq" and "toIndexedSeq", is very welcome.
Many thanks.
Regards,Germán
On Thu, Sep 23, 2010 at 7:17 PM, Germán Ferrari <german.ferrari@gmail.com> wrote:
Another (somewhat related) questions.
I've noticed that the default "IndexedSeq" is "collection.IndexedSeq" (like in "Seq") but the type of "toIndexedSeq" is "immutable.IndexedSeq".
Is this an error or is on purpose? maybe "IndexedSeq" should be by default "immutable.IndexedSeq"?
Thinking (erroneously) that "Seq" was by default "immutable.Seq", I was using it as the default type for the seq-like parameters of my methods. Now I'm thinking in change all source files using "Seq" to assure that "immutable.Seq" it's what is in scope.
What type do you use in such cases? "immutable.Seq" or anything else?
Sorry if this has been discussed previously. Any reference to the discussions regarding the default "Seq" and "IndexedSeq" and/or the return type of "toSeq" and "toIndexedSeq", is very welcome.
Many thanks.
Regards,Germán
On Thu, Sep 23, 2010 at 7:17 PM, Germán Ferrari <german.ferrari@gmail.com> wrote:
On Thu, Sep 23, 2010 at 6:33 PM, Lex <lexn82@gmail.com> wrote:
Java arrays are wrapped into WrappedArray to integrate with scala collection API. Arrays are used very often and WrappedArray is "mutable.Seq", so it makes sense for "Seq" to be the common supertype "scala.collection.Seq" by default.
This doesn't make sense to me. If I want a mutable Seq I'll use mutable.Seq as I have to do with Map and Set. Is there any documentation about this decision?
Sat, 2010-09-25, 10:07
#4
Re: Why Seq is not scala.collection.immutable.Seq
Wow, I did not know that!I agree: That's very confusing!
Heiko
On 23 September 2010 22:59, Germán Ferrari <german.ferrari@gmail.com> wrote:
--
Heiko Seeberger
Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Akka - Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Actors: akkasource.org
Heiko
On 23 September 2010 22:59, Germán Ferrari <german.ferrari@gmail.com> wrote:
Hi,
Without importing anything, Set refers to scala.collection.immutable.Set and Map to scala.collection.immutable.Map. Why Seq refers to scala.collection.Seq?
Welcome to Scala version 2.8.0.r22899-b20100902020112 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20). Type in expressions to have them evaluated.Type :help for more information.
scala> classOf[Seq[_]]res0: java.lang.Class[Seq[_]] = interface scala.collection.Seq
scala> classOf[Set[_]]res1: java.lang.Class[Set[_]] = interface scala.collection.immutable.Set
scala> classOf[Map[_,_]]res2: java.lang.Class[Map[_, _]] = interface scala.collection.immutable.Map
Regards,Germán
--
Heiko Seeberger
Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Akka - Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Actors: akkasource.org
Sat, 2010-09-25, 10:27
#5
Re: Why Seq is not scala.collection.immutable.Seq
On Fri, Sep 24, 2010 at 9:56 PM, Germán Ferrari <german.ferrari@gmail.com> wrote:
It's even more confusing than that, if you create an instance of collection.IndexedSeq or collection.Seq, you get something from collection.immutable:
package scala.collection object IndexedSeq extends SeqFactory[IndexedSeq] { ... def newBuilder[A]: Builder[A, IndexedSeq[A]] = immutable.IndexedSeq.newBuilder[A]}
package scala.collection object Seq extends SeqFactory[Seq] { ... def newBuilder[A]: Builder[A, Seq[A]] = immutable.Seq.newBuilder[A]}
Best,Ismael
I've noticed that the default "IndexedSeq" is "collection.IndexedSeq" (like in "Seq") but the type of "toIndexedSeq" is "immutable.IndexedSeq".
It's even more confusing than that, if you create an instance of collection.IndexedSeq or collection.Seq, you get something from collection.immutable:
package scala.collection object IndexedSeq extends SeqFactory[IndexedSeq] { ... def newBuilder[A]: Builder[A, IndexedSeq[A]] = immutable.IndexedSeq.newBuilder[A]}
package scala.collection object Seq extends SeqFactory[Seq] { ... def newBuilder[A]: Builder[A, Seq[A]] = immutable.Seq.newBuilder[A]}
Best,Ismael
Sat, 2010-09-25, 15:07
#6
Re: Why Seq is not scala.collection.immutable.Seq
On Sat, Sep 25, 2010 at 6:15 AM, Ismael Juma <mlists@juma.me.uk> wrote:
It's even more confusing than that, if you create an instance of collection.IndexedSeq or collection.Seq, you get something from collection.immutable:I see this more as a mitigation of the "problem" than a problem per se. I prefer that the default implementation of collection.Seq/IndexedSeq (returned by the apply method in the companion) be immutable.
On Thu, Sep 23, 2010 at 4:59 PM, Germán Ferrari <german.ferrari@gmail.com> wrote: