Attempting to implement code similar to that found in the higher-order-function example from http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-6
val button = new JButton("test")
button.addActionListener{ e:ActionEvent => println("test") }
add(button)
leads to the following
error: type mismatch;
found : (java.awt.ev...
Idle pondering from a Scala learner perhaps, but ... in my tinkerings I've written the following:
( n.child.size > 0 ) && ( n.child.filter( ! _.isInstanceOf[Text] ).size == 0 )
('n' is a scala.xml.Node, but that's not important. Nor is the particular logic.)
Calling child() twice isn't so good, so I was about to change it:
val list...
In Scala (2.7), if I have this function:
def foo(args: Array[String]) =
for (arg <- args) println(arg)
If I now try to define the following:
def bar(args: String*) = foo(args)
then the compiler complains:
<console>:5: error: type mismatch;
found : String*
required: Array[String]
def bar(args: String*) = foo(args)
...
After doing the whole "enterprise" programming for a while, I'm seriously disillusioned by the language itself and always feel quite hampered if I have to go back to it. The project size of your average Android app isn't too intimidating and the libraries are actually quite nice regarding their coding style, but if I could avoid Java, I'...
Hi,
I have installed latest scala ide plugin to eclipse (Version: 3.4.2). It seems installation is ok without any errors.
I am able to create a scala project and add a package, but i couldn't add scala object, at the time it shows "projectname" is not a Scala project error message in add object dialog.
I have googled and found it co...
Hello.
I installed Scala IDE for Eclipse, and it seems to be working okay. So now I'm trying to import a Lift project (specifically -- autogenerated Lift project from Stax application platform), and now I'm having four errors at my workspace:
value net is not a member of package <root> Boot.scala /rss2lj/src/scala/bootstrap/liftweb lin...
I have a case class
case class ~[a,b](_1:a, _2:b)
When I want to do pattetn matching
new ~("a", 25) match{
case "a" ~ 25 =>
}
I can use it this way because "a" ~ 25 and ~("a", 25) are equivalent. But if I want to match new ~("a", new ~("b", 25)) by {case "a" ~ "b" ~ 25 => } troubles begin. I understand that this statements aren't...
I am a bit confused by this ArithmeticException. I have tried this on Scala 2.8.0.RC6 and RC7.
scala> 7.12 to(8, 0.2)
res0: scala.collection.immutable.NumericRange[Double] = NumericRange(7.12, 7.32, 7.52, 7.72, 7.92)
scala> 7.12 to(8, 0.5)
res2: scala.collection.immutable.NumericRange[Double] = NumericRange(7.12, 7.62)
scala> 7.12 to...
This doesn't compile with Scala 2.7.7.final or 2.8.0.final for me:
new FileInputStream("test.txt") getChannel transferTo(
0, Long.MaxValue, new FileOutputStream("test-copy.txt") getChannel)
This does compile with Scala 2.7.7.final and 2.8.0.final for me:
new FileInputStream("test.txt") getChannel() transferTo(
0, Long.MaxValu...
Hi,
I'm fairly new to Scala, but I'm doing my exercises now.
I have a string like "A>Augsburg;B>Berlin". What I want at the end is a map
val mymap = Map("A"->"Augsburg", "B"->"Berlin")
What I did is:
val st = locations.split(";").map(dynamicListExtract _)
with the function
private def dynamicListExtract(input: String) = {
if (inp...
Which tools or libraries do you wish existed in the Scala ecosystem?
Are there any existing ones you wish were greatly improved?
...
How do you make a protected method in a class accessible to just all classes in the package in Scala?
...
There are a huge amount of tasks.
Each task is belong to a single group. The requirement is each group of tasks should executed serially just like executed in a single thread and the throughput should be maximized in a multi-core (or multi-cpu) environment. Note: there are also a huge amount of groups that is proportional to the number o...
I created a class Foo that has the method toArray() that returns an Array<Int>.
Now, I have a HashMap mapping Strings to HashMaps, which map Objects to Foo. That is:
HashMap<String,HashMap<Object,Foo>>
And I want to create a new object of type:
HashMap<String,HashMap<Object,Array<Int>>>
That is obtained by calling the function toA...
What I'd like to achieve is having a proper implementation for
def dynamix[A, B](a: A): A with B
I may know what B is, but don't know what A is (but if B has a self type then I could add some constraints on A).
The scala compiler is happy with the above signature, but I could not yet figure out how the implementation would look like -...
There seems to be a lot of enthusiasm among Scala bloggers lately for the type classes pattern, in which a simple class has functionality added to it by an additional class conforming to some trait or pattern. As a vastly oversimplified example, the simple class:
case class Wotsit (value: Int)
can be adapted to the Foo trait:
trait F...
I have an IntelliJ project with eight modules and roughly 500 KLines of Java. I added a Scala Facet to a module that depends on all the other modules.
When compiling HelloWorld.scala in IntelliJ IDEA 9.0.2:
object HelloWorld {
def main(args: Array[String]) {
println("Hello World!")
}
}
I got the following output in the Messa...
I downloaded scala 2.8 but when executing scala.bat it says
system cannot find set_home
I didn't have this problem with old version of scala.
So how to launch scala ?
Update: I'm on windows 7, I have setup JAVA_HOME environment variable. the problem is the set_home batch command that is not known.
I have found the official tutorial ...
I need iterate through a List but circular way. I need too add new elements to the list and iterate over all elements (olds and news elements), How I do it? Is there any data structure for them?
...
I'm trying to make an actor 'go to sleep' waiting for another actors signal. I want to do something like:
def act(){
loop{ //Should I use loop here too??
if(sleepy){
react{
//SLEEPING
case "Wake Up"=> sleepy=false; //just to breack the react
}
}else{
...