scala

Running a Scala app as a Java app

I'm trying to run the following rocket launching application: object HelloWorld { def main(args: Array[String]) { println("Hello World!") } } directly from java like this: java -cp scala-library.jar HelloWorld (obviously after compliling with scala) but get the following error: Exception in thread "main" java.lang...

Scala: convert a return type into a custom trait

I've written a custom trait which extends Iterator[A] and I'd like to be able to use the methods I've written on an Iterator[A] which is returned from another method. Is this possible? trait Increment[+A] extends Iterator[A]{ def foo() = "something" } class Bar( source:BufferedSource){ //this ain't working def getContents(...

Purely functional concurrent skip list

Skip lists (Pugh, 1990) provide sorted dictionaries with logarithmic-time operations like search trees but skip lists are much more amenable to concurrent updates. Is it possible to create an efficient purely functional concurrent skip list? If not, is it possible to create any kind of efficient purely functional concurrent sorted dicti...

Java compile speed vs Scala compile speed

I've been programming in Scala for a while and I like it but one thing I'm annoyed by is the time it takes to compile programs. It's seems like a small thing but with Java I could make small changes to my program, click the run button in netbeans, and BOOM, it's running, and over time compiling in scala seems to consume a lot of time. ...

scala type inference with _ place holder

List("This","is","Scala").foreach(a => print(a+" ")) compiles fine, but List("This","is","Scala").foreach(print(_+" ")) fails complaining of missing parameter type. I couldn't figure out why it fails. EDIT: I meant print not println - not that it makes logical difference. ...

Scala RAD tools

I am trying out on some application with Scala. I have been troubled a lot by its Swing support. Having to write the code seems to be painful. I love Netbeans Matisse function in this case. Is there any Scala RAD tools available? ...

What does it mean when I use def to define a field in Scala?

What exactly is the difference between: scala> def foo = 5 foo: Int and scala> def foo() = 5 foo: ()Int Seems that in both cases, I end up with a variable foo which I can refer to without parenthesis, always evaluating to 5. ...

how do I process returned Either

if a scala function is def A(): Either[Exception, ArrayBuffer[Int]] = { ... } what should be the right way to process the returned result? val a = A() and ? ...

Scala 2.8 tools for production use

What are your experiences with Scala tools currently used in production? Given that Scala 2.8 has been out for over a month, I thought it would be a good time for an update on the status of Scala tooling, along the lines of these questions. I'd like to broaden the scope of the questions beyond IDEs, to include RAD tools (e.g. JRebel), b...

Strange behavior with implicits

I'm using the Scalacheck library to test my application. In that library there's a Gen object that defines implicit conversions of any object to a generator of objects of that class. E.g., importing Gen._ lets you call methods such as sample on any object, through its implicit conversion to Gen: scala> import org.scalacheck.Gen._ impor...

Scala - calculate average of SomeObj.double in a List[SomeObj]

I'm on my second evening of scala, and I'm resisting the urge to write things in scala how I used to do them in java and trying to learn all of the idioms. In this case I'm looking to just compute an average using such things as closures, mapping, and perhaps list comprehension. Irrespective of whether this is the best way to compute a...

Why do compile-time generative techniques for structural typing prevent separate compilation?

I was reading (ok, skimming) Dubochet and Odersky's Compiling Structural Types on the JVM and was confused by the following claim: Generative techniques create Java interfaces to stand in for structural types on the JVM. The complexity of such techniques lies in that all classes that are to be used as structural types anywhere in the p...

when people say they run 'scala in the backend', in what context could they be talking about?

Say the use scala to process incoming email etc. In what context is (or could) they be running scala? Can it run inside its own daemon? Can it run inside of tomcat? Or would you use it in a cron job? or is it all of the above? :) Sorry this is an open question, and I don't know much about scala, but I just want an idea of how one ...

Anonymous functions and Maps in Scala

I'm not sure why this doesn't work: scala> case class Loader(n: String, x: String, l: List[String]) scala> val m: Map[String, (List[String])=>Loader] = | Map("x" -> Loader("x", "x1", _:List[String])) <console>:8: error: type mismatch; found : (List[String]) => (java.lang.String, Loader) required: (String, (List[...

Enabling Migration Warnings

I am porting a 2.7.7 scala code base over to 2.8 and was wondering if there was a compiler option to display migration notices? I was bitten by a change in behavior for mutable sequences that had the following migration notice[1], however it doesn't display anything when I build the project ( I have deprecation and unchecked warnings ena...

Is there an equivalent to SuppressWarnings in Scala?

I was wondering if scala had an equivalent to java's @SuppressWarnings that can be applied to a function or whatever to ignore any deprecation warnings[1] that function emits? 1: Relevant warning in my case is: method stop in class Thread is deprecated: see corresponding Javadoc for more information. I am aware of the problems with stop...

Does Scala have "type disjunction"?

One way that has been suggested to deal with double definitions of overloaded methods is to replace overloading with pattern matching: object Bar { def foo(xs: Any*) = xs foreach { case _:String => println("str") case _:Int => println("int") case _ => throw new UglyRuntimeException() } } This approach requires...

How can I call a function that takes 2 parameters with a Tuple2?

I have a function like so: def print(name:String, surname:String) { println(name + " " + surname) } I also have a Tuple2: val johnsmith = ("John", "Smith") When I call print with johnsmith I get the following error: scala> print(johnsmith) error: not enough arguments for meth...

Algorithm to calculate the number of combinations to form 100

Hi I am struck in a tricky situation where I need to calculate the number of combinations to form 100 based on different factors. Those are Number of combinations Multiplication factor distance Sample input 1: (2-10-20) It means list the valid 2 way combination to form 100. the distance between the combination should be less ...

all but the last item from a Scala Iterator (a.k.a. Iterator.init)

I have a number of large files where I want to process all but the last line in each file. If the files were small, I could just convert to a TraversableLike and use the "init" method, e.g.: lines.toList.init But the files are large so I need to keep things as an iterator. Is there a simple way to get something like "init" on an Itera...