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....
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...
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?
...
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 ...
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...
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...
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...
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...
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...
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...
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...
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...
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 ...
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: ?}
...
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>?
...
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?
...
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...
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...
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> 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?
...