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

Linearization in the scala REPL

6 replies
Jeff Olson
Joined: 2011-06-29,
User offline. Last seen 42 years 45 weeks ago.
Is there any way (presumably in power mode) to get the scala REPL to print out the linearization of a given type?
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Linearization in the scala REPL

On 8/10/11 2:43 PM, Jeff Olson wrote:
> Is there any way (presumably in power mode) to get the scala REPL to
> print out the linearization of a given type?

% rcscala -Dscala.repl.power
Welcome to Scala version 2.9.1.RC2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.

scala> class Bippy extends Immutable with Serializable
defined class Bippy

scala> intp.types("Bippy").tpe.baseTypeSeq.toList >
$line9.$read.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.Bippy
Serializable
ScalaObject
Immutable
java.io.Serializable
java.lang.Object
Any

Bippy is only that roundabout because I defined it in the repl. For a class already on the classpath:

scala> Nil.iterator.bts >
Iterator[A]
scala.collection.TraversableOnce[A]
scala.collection.GenTraversableOnce[A]
ScalaObject
java.lang.Object
Any

scala> :phase jvm
Active phase is now: Jvm

scala> Nil.bts >
scala.collection.immutable.Nil$
List
scala.collection.immutable.LinearSeq
scala.collection.immutable.Seq
scala.collection.LinearSeq
Seq
scala.collection.immutable.Iterable
Iterable
scala.collection.LinearSeqOptimized
scala.collection.LinearSeqLike
scala.collection.SeqLike
scala.collection.immutable.Traversable
scala.collection.GenSeq
Traversable
scala.collection.IterableLike
scala.collection.GenIterable
scala.collection.TraversableLike
scala.collection.GenTraversable
scala.collection.GenSeqLike
scala.collection.GenIterableLike
scala.collection.GenTraversableLike
PartialFunction
Product
scala.collection.TraversableOnce
scala.collection.generic.GenericTraversableTemplate
Serializable
Function1
scala.collection.GenTraversableOnce
scala.collection.Parallelizable
ScalaObject
Immutable
Equals
java.io.Serializable
scala.collection.generic.FilterMonadic
scala.collection.generic.HasNewBuilder
java.lang.Object
Any

rytz
Joined: 2008-07-01,
User offline. Last seen 45 weeks 5 days ago.
Re: Linearization in the scala REPL
i'd be using the :power mode much much more often if i didn't have to lookat its source code or ask on the mailing list every time i want to do something..
this sounds like a perfect fit for a document on https://wiki.scala-lang.org/ ! is somebody motivated to start such a page?
thanks: lukas

On Thu, Aug 11, 2011 at 04:56, Paul Phillips <paulp [at] improving [dot] org> wrote:
On 8/10/11 2:43 PM, Jeff Olson wrote:
> Is there any way (presumably in power mode) to get the scala REPL to
> print out the linearization of a given type?

% rcscala -Dscala.repl.power
Welcome to Scala version 2.9.1.RC2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.

scala> class Bippy extends Immutable with Serializable
defined class Bippy

scala> intp.types("Bippy").tpe.baseTypeSeq.toList >
$line9.$read.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.$iw.Bippy
Serializable
ScalaObject
Immutable
java.io.Serializable
java.lang.Object
Any


Bippy is only that roundabout because I defined it in the repl.  For a class already on the classpath:


scala> Nil.iterator.bts >
Iterator[A]
scala.collection.TraversableOnce[A]
scala.collection.GenTraversableOnce[A]
ScalaObject
java.lang.Object
Any


scala> :phase jvm
Active phase is now: Jvm

scala> Nil.bts >
scala.collection.immutable.Nil$
List
scala.collection.immutable.LinearSeq
scala.collection.immutable.Seq
scala.collection.LinearSeq
Seq
scala.collection.immutable.Iterable
Iterable
scala.collection.LinearSeqOptimized
scala.collection.LinearSeqLike
scala.collection.SeqLike
scala.collection.immutable.Traversable
scala.collection.GenSeq
Traversable
scala.collection.IterableLike
scala.collection.GenIterable
scala.collection.TraversableLike
scala.collection.GenTraversable
scala.collection.GenSeqLike
scala.collection.GenIterableLike
scala.collection.GenTraversableLike
PartialFunction
Product
scala.collection.TraversableOnce
scala.collection.generic.GenericTraversableTemplate
Serializable
Function1
scala.collection.GenTraversableOnce
scala.collection.Parallelizable
ScalaObject
Immutable
Equals
java.io.Serializable
scala.collection.generic.FilterMonadic
scala.collection.generic.HasNewBuilder
java.lang.Object
Any


extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Linearization in the scala REPL

On 8/11/11 12:32 AM, Lukas Rytz wrote:
> i'd be using the :power mode much much more often if i didn't have to
> look at its source code or ask on the mailing list every time i want
> to do something..

I keep thinking about documenting it, but I can't support any more code,
especially code which isn't written the way I want to write it, and I'm
afraid if I document it, people will expect it to keep working the way
it does.

I have a proposal which ends up with me documenting it.

1) I rearchitect the current contents of scala.tools.nsc.interpreter in
scala.repl putting all my hard-won knowledge of how to architect it to
work. I can keep the old interface mostly compatible while it goes
through deprecatation.

2) I also break it out as a separate component, in its own jar, as a
pretty easy step toward some modularization.

In exchange, I will:

1) define and support a stable repl API going forward
2) give the repl a configuration file and make everything configurable
3) abstract over operating environments (applets, GAE, etc)
4) include an API for exposing the compiler at various phases
5) document and stabilize power mode
6) other good things

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Linearization in the scala REPL


On Thu, Aug 11, 2011 at 5:45 PM, Paul Phillips <paulp [at] improving [dot] org> wrote:
On 8/11/11 12:32 AM, Lukas Rytz wrote:
i'd be using the :power mode much much more often if i didn't have to
look at its source code or ask on the mailing list every time i want
to do something..

I keep thinking about documenting it, but I can't support any more code, especially code which isn't written the way I want to write it, and I'm afraid if I document it, people will expect it to keep working the way it does.

I have a proposal which ends up with me documenting it.

1) I rearchitect the current contents of scala.tools.nsc.interpreter in scala.repl putting all my hard-won knowledge of how to architect it to work.  I can keep the old interface mostly compatible while it goes through deprecatation.
 
I think that's a good idea.
 
2) I also break it out as a separate component, in its own jar, as a pretty easy step toward some modularization.

Not sure about this one. Isn't the REPL intimately tied to the compiler? How big of a delta against it is it? I am against having a lot of small jars because it makes setup so much more difficult. Everyone of these has to be put into sbt, eclipse, standalone classpaths, etc. I am happy to have to deal with just scala-library and scala-compiler.

In exchange, I will:

1) define and support a stable repl API going forward
2) give the repl a configuration file and make everything configurable
3) abstract over operating environments (applets, GAE, etc)
4) include an API for exposing the compiler at various phases
5) document and stabilize power mode
6) other good things

That sounds like a good deal!

 -- Martin

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Linearization in the scala REPL

On 8/11/11 8:56 AM, martin odersky wrote:
> Not sure about this one. Isn't the REPL intimately tied to the compiler?

The repl is certainly dependent on the compiler, just not vice versa.
But this is the most expendable aspect of the proposal and I'm happy to
table it.

Jeff Olson
Joined: 2011-06-29,
User offline. Last seen 42 years 45 weeks ago.
Re: Linearization in the scala REPL
Awesome, thanks Paul!

I remember you talking about this at scala days, but I can't seem to find my notes. I don't suppose you saved your .scala_history?

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