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

Where did GenericArray disappear to?

8 replies
Erkki Lindpere
Joined: 2008-12-19,
User offline. Last seen 42 years 45 weeks ago.

It's not in the scala library bundled with the latest Eclipse plug-in
nightly (r21356)

Erkki L

ijuma
Joined: 2008-08-20,
User offline. Last seen 22 weeks 2 days ago.
Re: Where did GenericArray disappear to?

On Sun, Mar 7, 2010 at 6:34 PM, Erkki Lindpere wrote:
> It's not in the scala library bundled with the latest Eclipse plug-in
> nightly (r21356)

It was renamed to ArraySeq:

https://lampsvn.epfl.ch/trac/scala/changeset/21331

Ismael

Erkki Lindpere
Joined: 2008-12-19,
User offline. Last seen 42 years 45 weeks ago.
Re: Where did GenericArray disappear to?

Thanks.

It seems Trac does not search in affected filenames when searching
changesets (at least not moved ones).

Ismael Juma wrote:
> On Sun, Mar 7, 2010 at 6:34 PM, Erkki Lindpere wrote:
>
>> It's not in the scala library bundled with the latest Eclipse plug-in
>> nightly (r21356)
>>
>
> It was renamed to ArraySeq:
>
> https://lampsvn.epfl.ch/trac/scala/changeset/21331
>
> Ismael
>
>

ichoran
Joined: 2009-08-14,
User offline. Last seen 2 years 3 weeks ago.
Re: Where did GenericArray disappear to?
I never quite understood the point of GenericArray.  It basically duplicates WrappedArray's functionality, and awkwardly, because you can't use toArray and implicits to work with it.  Enhancing WrappedArray slightly seemed more sensible to me.  Maybe that's what happened?

(If that's not what happened, this is a vote for that to happen....)

  --Rex

On Sun, Mar 7, 2010 at 1:34 PM, Erkki Lindpere <erkki [at] lap [dot] ee> wrote:
It's not in the scala library bundled with the latest Eclipse plug-in nightly (r21356)

Erkki L

Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 4 days ago.
Re: Where did GenericArray disappear to?
Alright, let's go over this:
Array[T] - Benefits: Native, fast - Limitations: Few methods (only apply, update, length), need to know T at compile-time, because Java bytecode represents (char[] different from int[] different from Object[])
ArrayOps[T]:(Implicit conversions from Array[T] to ArrayOps[T] exist in Predef) - Benefits: Full suite of SeqLike methods, and these methods (e.g., map, filter, etc) can still return Array[T]  - Limitations: Not a subtype of Seq[T] (since methods return Array[T], which isn't a Seq[T]), need to know about T at compile-time (because it's backed by an Array[T])
WrappedArray[T]: (Implicit conversions from Array[T] to WrappedArray[T] exist in Predef, but are lower priority than implicits to ArrayOps[T]) - Benefits: Full suite of SeqLike methods, an actual subtype of Seq[T] (via the implicits, an Array[T] can be passed in to a method expecting a Seq[T])  - Mixed: SeqLike methods return Seq[T], not Array[T] (could be a benefit or a limitation; presumably you want this behavior, which is why you use WrappedArray[T] instead of ArrayOps[T])  - Limitations: You still need to know about T at compile-time (because it's backed by an Array[T])
ArraySeq[T] (the class formerly known as GenericArray[T]): - Benefits: Still backed by a native Array, don't need to know anything about T at compile-time (new ArraySeq[T] "just works", even if nothing is known about T), full suite of SeqLike methods, subtype of Seq[T]  - Limitations: It's backed by an Array[AnyRef], regardless of what T is (if T is primitive, then elements will be boxed/unboxed on their way in or out of the backing Array)
Yes, it kind of sucks that there are so many of them, and it's very confusing, but I hope I've convinced you that each of these classes has a reason for existing.
--j
On Wed, Apr 7, 2010 at 10:40 AM, Rex Kerr <ichoran [at] gmail [dot] com> wrote:
I never quite understood the point of GenericArray.  It basically duplicates WrappedArray's functionality, and awkwardly, because you can't use toArray and implicits to work with it.  Enhancing WrappedArray slightly seemed more sensible to me.  Maybe that's what happened?

(If that's not what happened, this is a vote for that to happen....)

  --Rex

On Sun, Mar 7, 2010 at 1:34 PM, Erkki Lindpere <erkki [at] lap [dot] ee> wrote:
It's not in the scala library bundled with the latest Eclipse plug-in nightly (r21356)

Erkki L


dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Where did GenericArray disappear to?
GenericArray[Any] is much faster than Array[Any] when handling primitives. In any code you have Array[T], where T isn't <: AnyRef, you'll get faster performance out of GenericArray. Or ArraySeq, as it is now called.

On Wed, Apr 7, 2010 at 2:40 PM, Rex Kerr <ichoran [at] gmail [dot] com> wrote:
I never quite understood the point of GenericArray.  It basically duplicates WrappedArray's functionality, and awkwardly, because you can't use toArray and implicits to work with it.  Enhancing WrappedArray slightly seemed more sensible to me.  Maybe that's what happened?

(If that's not what happened, this is a vote for that to happen....)

  --Rex

On Sun, Mar 7, 2010 at 1:34 PM, Erkki Lindpere <erkki [at] lap [dot] ee> wrote:
It's not in the scala library bundled with the latest Eclipse plug-in nightly (r21356)

Erkki L




--
Daniel C. Sobral

I travel to the future all the time.
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Where did GenericArray disappear to?

On Wed, Apr 07, 2010 at 12:01:24PM -0700, Jorge Ortiz wrote:
> WrappedArray[T]:
> ArraySeq[T] (the class formerly known as GenericArray[T]):

The major confusion reduction opportunity remaining is to alter the name
of one or both of those so the names communicate the distinction.

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Where did GenericArray disappear to?


On Wed, Apr 7, 2010 at 9:01 PM, Jorge Ortiz <jorge [dot] ortiz [at] gmail [dot] com> wrote:
Alright, let's go over this:
Array[T] - Benefits: Native, fast - Limitations: Few methods (only apply, update, length), need to know T at compile-time, because Java bytecode represents (char[] different from int[] different from Object[])
ArrayOps[T]:(Implicit conversions from Array[T] to ArrayOps[T] exist in Predef) - Benefits: Full suite of SeqLike methods, and these methods (e.g., map, filter, etc) can still return Array[T]  - Limitations: Not a subtype of Seq[T] (since methods return Array[T], which isn't a Seq[T]), need to know about T at compile-time (because it's backed by an Array[T])
WrappedArray[T]: (Implicit conversions from Array[T] to WrappedArray[T] exist in Predef, but are lower priority than implicits to ArrayOps[T]) - Benefits: Full suite of SeqLike methods, an actual subtype of Seq[T] (via the implicits, an Array[T] can be passed in to a method expecting a Seq[T])  - Mixed: SeqLike methods return Seq[T], not Array[T] (could be a benefit or a limitation; presumably you want this behavior, which is why you use WrappedArray[T] instead of ArrayOps[T])  - Limitations: You still need to know about T at compile-time (because it's backed by an Array[T])
ArraySeq[T] (the class formerly known as GenericArray[T]): - Benefits: Still backed by a native Array, don't need to know anything about T at compile-time (new ArraySeq[T] "just works", even if nothing is known about T), full suite of SeqLike methods, subtype of Seq[T]  - Limitations: It's backed by an Array[AnyRef], regardless of what T is (if T is primitive, then elements will be boxed/unboxed on their way in or out of the backing Array)
That's all correct. Except that I really see no case where you should declare an ArrayOps value explicitly.
It's really just a bridge to add methods to Array. I also think that WrappedArrays are mostly for internal use,
a means to make Arrays convertible to Seqs.

So that means you are left with Arrays/WrappedArrays one the one hand and ArraySeqs on the other hand, with the tradeoffs you describe.

Cheers

 -- Martin

Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 4 days ago.
Re: Where did GenericArray disappear to?
It'd be great if ScalaDoc could render the methods in ArrayOps as methods on Array. Then ArrayOps could be private[scala] or whatever and excluded from  ScalaDoc otherwise.
--j

On Wed, Apr 7, 2010 at 3:12 PM, martin odersky <martin [dot] odersky [at] epfl [dot] ch> wrote:


On Wed, Apr 7, 2010 at 9:01 PM, Jorge Ortiz <jorge [dot] ortiz [at] gmail [dot] com> wrote:
Alright, let's go over this:
Array[T] - Benefits: Native, fast - Limitations: Few methods (only apply, update, length), need to know T at compile-time, because Java bytecode represents (char[] different from int[] different from Object[])
ArrayOps[T]:(Implicit conversions from Array[T] to ArrayOps[T] exist in Predef) - Benefits: Full suite of SeqLike methods, and these methods (e.g., map, filter, etc) can still return Array[T]  - Limitations: Not a subtype of Seq[T] (since methods return Array[T], which isn't a Seq[T]), need to know about T at compile-time (because it's backed by an Array[T])
WrappedArray[T]: (Implicit conversions from Array[T] to WrappedArray[T] exist in Predef, but are lower priority than implicits to ArrayOps[T]) - Benefits: Full suite of SeqLike methods, an actual subtype of Seq[T] (via the implicits, an Array[T] can be passed in to a method expecting a Seq[T])  - Mixed: SeqLike methods return Seq[T], not Array[T] (could be a benefit or a limitation; presumably you want this behavior, which is why you use WrappedArray[T] instead of ArrayOps[T])  - Limitations: You still need to know about T at compile-time (because it's backed by an Array[T])
ArraySeq[T] (the class formerly known as GenericArray[T]): - Benefits: Still backed by a native Array, don't need to know anything about T at compile-time (new ArraySeq[T] "just works", even if nothing is known about T), full suite of SeqLike methods, subtype of Seq[T]  - Limitations: It's backed by an Array[AnyRef], regardless of what T is (if T is primitive, then elements will be boxed/unboxed on their way in or out of the backing Array)
That's all correct. Except that I really see no case where you should declare an ArrayOps value explicitly.
It's really just a bridge to add methods to Array. I also think that WrappedArrays are mostly for internal use,
a means to make Arrays convertible to Seqs.

So that means you are left with Arrays/WrappedArrays one the one hand and ArraySeqs on the other hand, with the tradeoffs you describe.

Cheers

 -- Martin


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