scala

Scala Remote Actor Message type woes

So I've been playing around with remote actors, and I've run into some difficulties with serialization exceptions. One of my message is an instance of a case class, which itself contains an instance of a list of Path classes. The Path class is defined as follows, and is essentially a collection of Point instances with a precomputed dista...

Receiving HTTP request params in Lift

I'm a Lift newbie and I can't digest it's HTTP request/response cycle yet. Handling REST is thoroughly explained in Lift docs but what I'm looking for is much simpler: how do I access HTTP request body/params in my web service (in Scala code of course) ? ...

Which CI server works with SBT?

I'm considering using SBT for a new scala project, but I'm not sure which CI server - hudson / cruise / whatever has support for it. Any ideas? I know SBT is a little Maven like, but I don't think it can work as a drop in replacement for Maven in the eyes of a CI server. ...

Scala equivalent of Google Collections Lists.partition

I am looking for a function that will partition a list into fixed size sublists, exactly what Lists.partition from Google Collections library does. I couldn't find such method in the Scala Collections API. Am I missing something? ...

Is it correct to define all classes as cases in Scala just to have all their arguments made properties automatically?

I'm beginning Scala. Am I correct understanding that I should define a class as a case class if I'd like it's arguments to be exposed as properties? Does not it introduce any side effects? ...

In Scala, how to stop reading lines from a file as soon as a criterion is accomplished?

Reading lines in a foreach loop, a function looks for a value by a key in a CSV-like structured text file. After a specific line is found, it is senseless to continue reading lines looking for something there. How to stop as there is no break statement in Scala? ...

VIM and Scala -- indentation problems?

I downloaded Scala 2.8, installed the vim scripts included and tried to type in some Scala code. When I typed in val x = 1 + 2 and hit ENTER, the indentation goes to below the v. When I type in val x = (1 + 2), the indentation is below the x! If VIM is used by anyone at all for Scala, this bug should've been seen long ago. Or am I the ...

Why does IntelliJ IDEA compile Scala so slowly?

I am using idea 9.0.3 which is the latest release. When I write some scala source code in Idea, it takes several seconds to compile and run. This shouldn't be that slow, Is this normal? ...

Right way to swap x elements in List

I started to learn Scala language and I have a question. How do you think, is it a right way to swap first and last x elements in List in a functional style? def swap(l: List[Any], x: Int) = { val l1 = l.take(x) val l2 = l.slice(x, l.length - x) val l3 = l.takeRight(x) l3 ::: l2 ::: l1 } It doesn't matter what happened if x wo...

Can you suggest any good intro to Scala philosophy and programs design?

In Java and C++ designing program's objects hierarchy is pretty obvious. But beginning Scala I found myself difficult to decide what classes to define to better employ Scala's syntactic sugar facilities (an even idealess about how should I design for better performance). Any good readings on this question? ...

In Scala, how to read a simple CSV file having a header in it's first line?

The task is to look for a specific field (by it's number in line) value by a key field value in a simple CSV file (just commas as separators, no field-enclosing quotes, never a comma inside a field), having a header in it's first line. User uynhjl has given an example (but with a different character as a separator): val src = Source....

Lift vs. Others

anyone have any experience with lift and how it compares to more widely used frameworks like rails and django? ...

What's the standard way to work with dates and times in Scala? Should I use Java types or there are native Scala alternatives?

What's the standard way to work with dates and times in Scala? Should I use Java types such as java.util.Date or there are native Scala alternatives? ...

Emacs scala-mode newline-and-indent weirdness

I have the following code in Emacs under scala-mode (from the Scala 2.8 package): object t1 { def main (args: List[String]) = { println("Hello") } } I also have my return key set to newline-and-indent. When I repeatedly hit return after the last brace, it goes to the leftmost column for one blank line. When I press return agai...

Implementing a Java interface method in Scala

My implementation of a getHandler method, which is defined on a Java interface, has failed, and I don't know why. Here is the method signature: <H extends EventHandler> H getHandler( Type<H> type, int index ); My implementation in Scala is: def getHandler[H <: com.google.gwt.event.shared.EventHandler] (aType: Type[H], index: Int)...

How can I convert this foldLeft : Double expression to use Option[Double] instead?

Can anyone help this Scala newbie? Previously, we summed a number of quantities in a list of entities with those quantities with: sum = entities.foldLeft(0.0)(_ + _.quantity) Now the quantity is an Option[Double], and so is the sum. How can I convert this using idiomatic Scala? If any entity's quantity is None then the sum should als...

Formally constructing Control Flow Graph

Hi, Im writing a compiler for university project, and I would like to transform my Abstract Syntax Tree into a Control Flow Graph(CFG). Im thinking that the nodes(V) in the CFG should be nodes from the AST. I know algorithmically how to construct the edge set (G=(V,E)) but Im having a hard time writing the process a bit more formally ...

Weird Type Mismatch in Scala

Hi I hope this question hasn't been answered yet somewhere else. Didn't find an answer here. In my localisation system I've got a class named Language class Language(val name:String, dict:HashMap[String, String]) { def apply(key: String):String = (dict get key) match { case None => "°unknown°" case Some(s) => s } //...

Why can't I write println "Hello world" in Scala?

I'm pretty new to Scala, but I thought that one of the strengths of the language was to remove the ceremony, like paranthesis and dots, that exists in for instance Java. So I was pretty confused when I discovered that I can write for instance str1 equals str2 but not println "Hello world" I have surmised that it has something to d...

What does "recursive method <method name> needs type" in Scala mean?

When I try to omit dots from method invocations, like in this example program: object Test extends Application { val baz = new Baz var foo = baz bar println(foo) } class Baz { def bar = "bar" } I get strange errors. The first one is error: recursive method foo needs type: println foo and the other one is error: type mismatch;...