Newbie Scala Question:
Say I want to do this [Java code] in Scala:
public static double[] abs(double[] r, double[] im) {
double t[] = new double[r.length];
for (int i = 0; i < t.length; ++i) {
t[i] = Math.sqrt(r[i] * r[i] + im[i] * im[i]);
}
return t;
}
and also make it generic (since Scala efficiently do generic primit...
Hi all. I'm drawing a tab and I have the outline as I want it.
I now want to fill the area I create but can't figure out how.
This is the code that draws the border of the tab:
val g2 = g.asInstanceOf[Graphics2D]
g2.translate(x, y)
val q = new CubicCurve2D.Float
q.setCurve(0, h, 8, h, 6, 0, 16, 0)
g2.setColor(Color.RED)
g2...
Hi,
I have the following classes/traits in Scala
trait Write[-T] {
def add(elem : T);
}
class ContraListWrapper[T] (var list : List[T]) extends Write[T] {
def add(elem : T) = {
list = elem :: list
}
}
def bar(list : Write[Number]) = {}
Invoking the method with a List of Object or list of Numbers works, thanks to contr...
Hi,
When I'm writing this code, I've got a Compile error in Scala
var s: Stack[_ <: Number] = new Stack[Integer];
s.push(new Integer(1)); //compile-error: type mismatch; found :Integer required: _$bqjyh where type _$bqjyh <: Number
s.push(null); //compile-error: type mismatch; found : Null(null) required: _$2 where type _$2 <: Objec...
How one can access attributes with namespaces? My XML data are in a form
val d = <z:Attachment rdf:about="#item_1"></z:Attachment>
but the following does not match the attribute
(d \\ "Attachment" \ "@about").toString
If I remove the namespace component from the attribute's name then it works.
val d = <z:Attachment about="#item_1"...
Hello,
As I am in my starting career year in software development (C++ & C#) I now see my flaws and what I miss in this sphere. Because of that I came into some conclusions and made myself a plan to fill those gaps and increase my knowledge in software development. But the question I stumbled upon after making a tasks which I need to do...
In scalacheck's user guide there is "Generating Case Classes" paragraph. I modified example from it to use regular classes instead of case classes:
import org.scalacheck._
import Gen._
import Arbitrary._
sealed abstract class Tree
object Leaf extends Tree
class Node(left:Tree, rigth:Tree, v:Int) extends Tree
object Main {
val genLe...
Hi, im new to scala and ran into the following problem:
I want to get a subcollection of an existing collection that only contains elements of a specific type. The following works:
class C(val name : String)
class D(name : String) extends C(name) { }
val collection = Set[C](new C("C1"),new D("D1"),new C("C2"),new D("D2"))
collection.c...
Chained package clause were introduced in Scala 2.8, as described by Martin Odersky on the Scala site.
I don't quite get the intuition behind this.
Following was the example in the Scala book for the nested packages:
package bobsrockets {
package navigation {
// In package bobsrockets.navigation
class Navigator
...
I am using SBT (0.7.4) with Scala(2.7.7) to build my Scala project and sometimes I get following error when building the project.
So far the only remedy seems to retry it or do a clean on the SBT shell which adds delay in build process. No definite pattern of occurrence of the error has emerged but it happens quite a lot when I am using...
Are there any good Scala-specific frameworks (for whatever purpose) and libraries worth taking a look out there other than Lift web framework?
...
Hi,
In Scala variance can be defined with variance operators like + and - on the generic type argument. For example the List type is covariant in the standard library.
class List[+A]
So a function with a covariant list can be defined like this:
def foo[A](list : List[A])
Also variance can be emulated with generic bounds. So we can...
What kind of constructs need 'scalac' compile and how to make an equivalent that will work in interpreter?
Edit: I want to use scala instead of python as a scripting language. (with #!/usr/bin/scala)
...
haskell programmer. using F#. no typeclasses in F#. what to use when I need typeclasses?
...
I have Scala 2.8.0 installed and don't wish to use Scala 2.7. Whenever I try to use SBT, it begins downloading Scala 2.7.7. Even if I call it in a directory with a Scala 2.8 project. How to avoid this behaviour? There is no man page for SBT, neither I could find SBT configuration files in /etc or ~/.
...
How to use colours in console output in Scala or Java?
...
UserGuide of scalacheck project mentioned sized generators. The explanation code
def matrix[T](g:Gen[T]):Gen[Seq[Seq[T]]] = Gen.sized {size =>
val side = scala.Math.sqrt(size).asInstanceOf[Int] //little change to prevent compile-time exception
Gen.vectorOf(side, Gen.vectorOf(side, g))
}
explained nothing for me. After some explorat...
What exactly is the difference between StandardTokenParsers and JavaTokenParsers?
What is one good for and what is the other good for?
In StandardTokenParsers I can define my keywords using lexical.reserved, but how exactly does that help me?
BR Troels
...
I'm stuck on whether I should focus on Play or Lift for doing web development in Scala.
Play looks very polished. The Scala-specific tutorial looks amazing. Furthermore, since I've been coding in MVC frameworks for a long time, it looks super familiar. However, it doesn't look like it can easily accomplish all the brilliant things th...
Hi stackoverflow.
Having a background in Haskell I am currently trying to get familiar with Scala.
I encountered some problems trying to translate a small, extensible expression language from Haskell into Scala. The underlying issue of writing a data type that is extensible with both new data-variants and operations is commonly known a...