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

LinearSeq and head/tail decomposition

4 replies
Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.

If LinearSeq is the trait that denotes efficient head/tail splitting, why is there no extractor like :: for LinearSeq?  Am I missing something in the library?

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: LinearSeq and head/tail decomposition


On Thu, Jun 23, 2011 at 2:33 AM, Josh Suereth <joshua.suereth@gmail.com> wrote:
If LinearSeq is the trait that denotes efficient head/tail splitting, why is there no extractor like :: for LinearSeq?  Am I missing something in the library?

We wanted to keep to the principle that extractors mirror constructors. Since only list has '::', it made sense to restrict the extractor to lists. One could
think of defining '::' more generally, but then, that would be backwards incompatible, and I do not know what the performance implications for list would be.

Cheers

 -- Martin


Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: LinearSeq and head/tail decomposition

what would you think of an extractor named +: defined for linearseq?  I'll run some performance tests.

On Jun 23, 2011 3:35 AM, "martin odersky" <martin.odersky@epfl.ch> wrote:
> On Thu, Jun 23, 2011 at 2:33 AM, Josh Suereth <joshua.suereth@gmail.com>wrote:
>
>> If LinearSeq is the trait that denotes efficient head/tail splitting, why
>> is there no extractor like :: for LinearSeq? Am I missing something in the
>> library?
>
>
> We wanted to keep to the principle that extractors mirror constructors.
> Since only list has '::', it made sense to restrict the extractor to lists.
> One could
> think of defining '::' more generally, but then, that would be backwards
> incompatible, and I do not know what the performance implications for list
> would be.
>
> Cheers
>
> -- Martin
Kevin Wright 2
Joined: 2010-05-30,
User offline. Last seen 26 weeks 4 days ago.
Re: LinearSeq and head/tail decomposition


On 23 June 2011 13:29, Josh Suereth <joshua.suereth@gmail.com> wrote:

what would you think of an extractor named +: defined for linearseq?  I'll run some performance tests.


I was thinking of exactly the same thing... Performance aside though, is there any reason not to pull it further up the hierarchy, to Seq?

 
On Jun 23, 2011 3:35 AM, "martin odersky" <martin.odersky@epfl.ch> wrote:
> On Thu, Jun 23, 2011 at 2:33 AM, Josh Suereth <joshua.suereth@gmail.com>wrote:
>
>> If LinearSeq is the trait that denotes efficient head/tail splitting, why
>> is there no extractor like :: for LinearSeq? Am I missing something in the
>> library?
>
>
> We wanted to keep to the principle that extractors mirror constructors.
> Since only list has '::', it made sense to restrict the extractor to lists.
> One could
> think of defining '::' more generally, but then, that would be backwards
> incompatible, and I do not know what the performance implications for list
> would be.
>
> Cheers
>
> -- Martin



--
Kevin Wright

gtalk / msn : kev.lee.wright@gmail.comkev.lee.wright@gmail.commail: kevin.wright@scalatechnology.com
vibe / skype: kev.lee.wrightquora: http://www.quora.com/Kevin-Wright
twitter: @thecoda

"My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger" ~ Dijkstra
Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: LinearSeq and head/tail decomposition
You could go all the way to Traversable.   I'm more of the opinion that doing head/tail decompositional algorithms belongs at LinearSeq *for* performance reasons.   LinearSeq is supposed to guarantee 'efficient' head/tail decomposition, so it should support a handy mechanism to create these algorithms for all such collections.
I think if you wanted to use Seq or higher, different styles of algorithms will serve you better.  After all, why have a rich collection hierarchy with performance 'pseduo-guarantees' if we don't plan to leverage that?

- Josh

On Thu, Jun 23, 2011 at 9:30 AM, Kevin Wright <kev.lee.wright@gmail.com> wrote:


On 23 June 2011 13:29, Josh Suereth <joshua.suereth@gmail.com> wrote:

what would you think of an extractor named +: defined for linearseq?  I'll run some performance tests.


I was thinking of exactly the same thing... Performance aside though, is there any reason not to pull it further up the hierarchy, to Seq?

 
On Jun 23, 2011 3:35 AM, "martin odersky" <martin.odersky@epfl.ch> wrote:
> On Thu, Jun 23, 2011 at 2:33 AM, Josh Suereth <joshua.suereth@gmail.com>wrote:
>
>> If LinearSeq is the trait that denotes efficient head/tail splitting, why
>> is there no extractor like :: for LinearSeq? Am I missing something in the
>> library?
>
>
> We wanted to keep to the principle that extractors mirror constructors.
> Since only list has '::', it made sense to restrict the extractor to lists.
> One could
> think of defining '::' more generally, but then, that would be backwards
> incompatible, and I do not know what the performance implications for list
> would be.
>
> Cheers
>
> -- Martin



--
Kevin Wright

gtalk / msn : kev.lee.wright@gmail.comkev.lee.wright@gmail.commail: kevin.wright@scalatechnology.com
vibe / skype: kev.lee.wrightquora: http://www.quora.com/Kevin-Wright
twitter: @thecoda

"My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger" ~ Dijkstra

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