scala-2.8

In Scala 2.8 collections, why was the Traversable type added above Iterable?

I know that to be Traversable, you need only have a foreach method. Iterable requires an iterator method. Both the Scala 2.8 collections SID and the "Fighting Bitrot with Types" paper are basically silent on the subject of why Traversable was added. The SID only says "David McIver... proposed Traversable as a generalization of Iterable....

cannot override a concrete member without a third member that's overridden by both

What does the following error message mean? cannot override a concrete member without a third member that's overridden by both (this rule is designed to prevent ``accidental overrides''); I was trying to do stackable trait modifications. It's a little bit after the fact since I already have a hierarchy in place and I'm tryi...

Which IDE for Scala 2.8?

This is the same question for older version of Scala, but they say that Eclipse plugin has been improved vastly. Is it the best IDE now? How do different Scala IDE compare today? ...

Scala Type Failure in 2.7: is there a workaround?

I have a problem using a parameterized class as the key-type of a Map. First create the parameterized class: scala> sealed abstract class Foo[T]{ def t: T } defined class Foo Now create some imaginary collection of these across unknown parameters: scala> var l: List[Foo[_]] = Nil l: List[Foo[_]] = List() Now create a Map to store ...

Need help with Continuations-Error "found cps expression in non-cps position"

I try building the following simple Generator using the Scala 2.8 Continuations-PlugIn. Where does the following error come from? None/None/Some((Unit,Unit)) GenTest.scala:8: error: found cps expression in non-cps position yieldValue(1) None/None/Some((Unit,Unit)) GenTest.scala:9: error: found cps expression in non-cps position...

How to access a field's value via reflection (Scala 2.8)

Consider the following code: class Foo(var name: String = "bar") Now i try to get the value and the correct type of it via reflection: val foo = new Foo val field = foo.getClass.getDeclaredField("name") field.setAccessible(true) //This is where it doesn't work val value = field.get(????) I tried things like field.get(foo), but that...

Is classOf[] in Scala 2.8 different from 2.7?

I have an interface from Java public class IJava { ... public java.lang.Class getType(); ... } It is inherited in Scala class CScala { def getType() = classOf[Foo] } It worked in Scala 2.7.7. But in 2.8.0.RC1, I get type mismatch; found : java.lang.Class[Foo](classOf[Foo]) required: java.lang.Class How do I get...

Scala: is it possible to override default case class constructor?

Just wondering if this is possible. What I would actually like to do is check and possibly modify one of the arguments before it is stored as a val. Alternatively, I could use an overload and make the default constructor private. In which case I would also like to make private the default factory constructor in the companion object, how...

Is there an easy (idiomatic) way to convert a java.lang.reflect.Method to a Scala function?

Can I retrieve a Method via reflection, somehow combine it with a target object, and return it as something that looks like a function in Scala (i.e. you can call it using parenthesis)? The argument list is variable. It doesn't have to be a "first-class" function (I've updated the question), just a syntactic-looking function call, e.g. f...

How to unimport String "+" operator in Scala?

I'm writing a DSL where the "+" operator is strictly numeric, like some other popular languages. It's close, but the String "+" operator is messing up my implicit conversions. What's the syntax for unimporting an operator of the String class? Just to be clearer, instead of this: scala> var x = "2" + 3; x: java.lang.String = 23 I'd l...

Implementing Seq[T] for CPS-Classes

Having the following class which is in a CPS-context (@cps[Unit]) how would I implement the Seq-trait? Do I have to leave the standard traits like Seq aside and just implement map, flatmap and foreach in the cps-context? class DataFlowVariable[T] { def apply(): T @cps[Unit] = ... } class DataFlowStream[T] extends Seq[T] { override...

How to use Scala in IntelliJ IDEA (or: why is it so difficult to get a working IDE for Scala)?

I recently gave up trying to use Scala in Eclipse (basic stuff like completion doesn't work). So now I'm trying IntelliJ. I'm not getting very far. I've been able to edit programs (within syntax highlighting and completion... yay!). But I'm unable to run even the simplest "Hello World". This was the original error: Scala signature Pr...

Have you actually convinced anybody to Scala?

I had limited success myself. I was able to hype a few persons about Scala. But in fact none of them made a meaningful effort to try to switch (usually from Java). I would like to read both success and failure stories here. Both long tries and short ones. My goal is to find ways of presenting Scala to another person, friend, co-worker ...

Simple Scala syntax - trying to define "==" operator - what am I missing?

While experimenting with some stuff on the REPL, I got to a point where I needed something like this: scala> class A(x:Int) { println(x); def ==(a:A) : Boolean = { this.x == a.x; } } Just a simple class with an "==" operator. Why doesn't it work??? Here's the result: :10: error: type mismatch; found : A required: ?{val x: ?} ...

Why scala 2.8 REPL does not auto-complete some method (i.e. forall, exists)?

I started the scala REPL an write the following code: scala> val a = Array(1,2,3,4) a: Array[Int] = Array(1, 2, 3, 4) scala> a.`<TAB>` asInstanceOf getClass isInstanceOf toString scala> a.exists(_ == 1) res1: Boolean = true Why I don't have "exists" listed when I press <TAB>? ...

What compromises Scala made to run on JVM?

Scala is a wonderful language, but I wonder how could be improved if it had it's own runtime? I.e. what design choices were made because of JVM choice? ...

Scala puts precedence on implicit conversion over "natural" operations... Why? Is this a bug? Or am I doing something wrong?

This simple test, of course, works as expected: scala> var b = 2 b: Int = 2 scala> b += 1 scala> b res3: Int = 3 Now I bring this into scope: class A(var x: Int) { def +=(y:Int) { this.x += y } } implicit def int2A(i:Int) : A = new A(i) I'm defining a new class and a += operation on it, and a convenient implicit...

How do I enable continuations on Scala 2.8?

Scala 2.8.0.RC1 includes the continuations plugin on trunk for the first time, but the details of how to get access to the shift and reset operations have changed from previous releases, so it's difficult to follow the blog entries and SO answers out there that talk about continuations but were written for previous versions. See also ht...

Scala 2.8 TreeMap and custom Ordering

I'm switching from scala 2.7 and ordered to scala 2.8 and using ordering. It looks quite straight forward but I was wondering could I make it a little less verbose. For example: scala> case class A(i: Int) defined class A scala> object A extends Ordering[A] { def compare(o1: A, o2: A) = o1.i - o2.i} defined module A If I then try to c...

Scala Array constructor?

scala> val a = Array [Double] (10) a: Array[Double] = Array(10.0) scala> val a = new Array [Double] (10) a: Array[Double] = Array(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) Why these two expressions have different semantics? ...