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

these views are amazing, and I love the fresh air!

2 replies
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.

When views were introduced I'm sure this seemed pretty reasonable.

trait SequenceView[+UC[+B] <: Sequence[B], +A]

Now behold the leviathan it has wrought! Tremble before its mighty
boilerplate!

trait ParSeqViewLike[+T,
+Coll <: Parallel,
+CollSeq,
+This <: ParSeqView[T, Coll, CollSeq] with
ParSeqViewLike[T, Coll, CollSeq, This, ThisSeq],
+ThisSeq <: SeqView[T, CollSeq] with
SeqViewLike[T, CollSeq, ThisSeq]]
extends SeqView[T, Coll]
with SeqViewLike[T, Coll, This]
with ParIterableView[T, Coll, CollSeq]
with ParIterableViewLike[T, Coll, CollSeq, This, ThisSeq]
with ParSeq[T]
with ParSeqLike[T, This, ThisSeq]

It doesn't stop with the class declaration. ParSeqViewLike is 180 lines
and I am hard pressed to find five which aren't boilerplate.

This is not entirely idle interest. After achieving a five order of
magnitude speed gain I got cocky and thought I'd dash off some set and
map views. How wrong I was. Only code generation has much hope of
pushing views any further in this direction (not to mention dealing with
the existing bugs) but what I'm here to ask is whether there isn't a
better way.

Off the top of my head I'd throw out inheritance and see where that took
me. What else you got?

(The subject line is from "a girl and her gator" if you want to know
what I'm reading these days.)

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: these views are amazing, and I love the fresh air!


On Tue, Mar 15, 2011 at 6:52 AM, Paul Phillips <paulp@improving.org> wrote:
When views were introduced I'm sure this seemed pretty reasonable.

 trait SequenceView[+UC[+B] <: Sequence[B], +A]

Now behold the leviathan it has wrought! Tremble before its mighty boilerplate!

trait ParSeqViewLike[+T,
                    +Coll <: Parallel,
                    +CollSeq,
                    +This <: ParSeqView[T, Coll, CollSeq] with ParSeqViewLike[T, Coll, CollSeq, This, ThisSeq],
                    +ThisSeq <: SeqView[T, CollSeq] with SeqViewLike[T, CollSeq, ThisSeq]]
extends SeqView[T, Coll]
  with SeqViewLike[T, Coll, This]
  with ParIterableView[T, Coll, CollSeq]
  with ParIterableViewLike[T, Coll, CollSeq, This, ThisSeq]
  with ParSeq[T]
  with ParSeqLike[T, This, ThisSeq]

It doesn't stop with the class declaration.  ParSeqViewLike is 180 lines and I am hard pressed to find five which aren't boilerplate.

Yes, I feel with you. Views were inherited from the pre 2.8 collections. Pre 2.8 their boilerplate did not stick out very much, but now it does. I know boilerplate could be reduced of we had virtual classes (because views essentially are implemented in the virtaul class pattern). But I don't see virtual classes arriving anytime soon.

If there's an alternative design that avoids the boilerplate that would be great, of course.

Cheers

 -- Martin

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: these views are amazing, and I love the fresh air!


On Tue, Mar 15, 2011 at 6:52 AM, Paul Phillips <paulp@improving.org> wrote:
When views were introduced I'm sure this seemed pretty reasonable.

 trait SequenceView[+UC[+B] <: Sequence[B], +A]

Now behold the leviathan it has wrought! Tremble before its mighty boilerplate!

trait ParSeqViewLike[+T,
                    +Coll <: Parallel,
                    +CollSeq,
                    +This <: ParSeqView[T, Coll, CollSeq] with ParSeqViewLike[T, Coll, CollSeq, This, ThisSeq],
                    +ThisSeq <: SeqView[T, CollSeq] with SeqViewLike[T, CollSeq, ThisSeq]]
extends SeqView[T, Coll]
  with SeqViewLike[T, Coll, This]
  with ParIterableView[T, Coll, CollSeq]
  with ParIterableViewLike[T, Coll, CollSeq, This, ThisSeq]
  with ParSeq[T]
  with ParSeqLike[T, This, ThisSeq]

I've always wanted a huge inheritance.
 

It doesn't stop with the class declaration.  ParSeqViewLike is 180 lines and I am hard pressed to find five which aren't boilerplate.

This is not entirely idle interest.  After achieving a five order of magnitude speed gain I got cocky and thought I'd dash off some set and map views.  How wrong I was.  Only code generation has much hope of pushing views any further in this direction (not to mention dealing with the existing bugs) but what I'm here to ask is whether there isn't a better way.

Off the top of my head I'd throw out inheritance and see where that took me.  What else you got?

(The subject line is from "a girl and her gator" if you want to know what I'm reading these days.)



--
Viktor Klang,
Code Connoisseur
Work:   Scalable Solutions
Code:   github.com/viktorklang
Follow: twitter.com/viktorklang
Read:   klangism.tumblr.com

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