scala

How does Scala scale on a cluster?

I have been learning Erlang, but also I'm keeping my eyes open to other technologies such as Scala. Does anyone know how Scala's multi node performance compares to Erlang? ...

Merge sort from "Programming Scala" causes stack overflow

A direct cut and paste of the following algorithm: def msort[T](less: (T, T) => Boolean) (xs: List[T]): List[T] = { def merge(xs: List[T], ys: List[T]): List[T] = (xs, ys) match { case (Nil, _) => ys case (_, Nil) => xs case (x :: xs1, y :: ys1) => if (less(x, y)) x :: merge(xs1, ys) e...

Implementing yield (yield return) using Scala continuations

How might one implement C# yield return using Scala continuations? I'd like to be able to write Scala Iterators in the same style. A stab is in the comments on this Scala news post, but it doesn't work (tried using the Scala 2.8.0 beta). Answers in a related question suggest this is possible, but although I've been playing with delimited...

Reflection API for Scala

Does anyone know the status of a fully-featured reflection API for Scala? I know that you can use Java's reflection API to do simple things but this does not work well with Scala's language features. I found an interesting article describing an experimental Scala Mirroring API but as far as I know this is still experimental. I've als...

Scala Catalog of functional Design Patterns

Since a week I'm reading Programming in Scala. The authors introduce elements of the language step by step , but I'm still confused when to use the functional things like actors, closures, currying,.... I'm looking for a catalog of typical use cases or best practices for functional contructs. I don't mean reimplementing well known pa...

Functional language implementations of Production Grade data stores

There are many datastores written in Erlang, for example Riak, Dynomite, CouchDb, Scalaris, have I missed any? I know that Java and C/C++ have also been used to write datastores (Cassandra, Hypertable, etc), but have any Datastores been written in any other functional languages such as F#, Scala, Haskell, Clojure, etc? The reason I am a...

What Automatic Resource Management alternatives exists for Scala?

I have seen many examples of ARM (automatic resource management) on the web for Scala. It seems to be a rite-of-passage to write one, though most look pretty much like one another. I did see a pretty cool example using continuations, though. At any rate, a lot of that code has flaws of one type or another, so I figured it would be a goo...

Scala: Parallel assignment of Tuples

Is it possible to assign tuple members in parallel in Scala. if not is there another technique to accomplish something similar? val players = List( new Player("Django Reinhardt", 42), new Player("Sol Hoopii", 57), new Player("Marc Ribot", 64) ) val winners, losers = players.partition(p => p.score > 50) // winners = List...

Scala programmer - "should there be one obvious way to do it" or "more than one way to do it"?

I have been doing Java for a long time and started Scala about 6 months ago. I love the language. One thing that I discovered is that there are multiple ways to do things. I don't know if it is because of the nature of the language or because it's still young and evolving and idioms and best practices haven't emerged. What surprises me ...

Type Inference on Method Return Type

Why does Scala fail to infer the return type of the method when there's explicit return statement used in the method? For instance, why does the following code compile : object Main { def who = 5 def main(args: Array[String]) = println(who) } ...but the following doesn't : object Main { def who = return 5 def main(args: Arra...

How can I use map and receive an index as well in Scala?

Is there any List/Sequence built-in that behaves like map and provides the element's index as well? ...

Scala project does not automatically build in Eclipse

I copied the examples folder from scala-2.7.7.final-devel-docs to the src folder of a scala project. But the source files will not compiled unless I change them manually. "Project/Build automatically" is checked. I'm using the Scala Eclipse Plugin 2.7.7-final How can I achieve that this works like in java projects? ...

Scala XSD library

What are the options for querying XSD files in Scala. The standard XML library is of course one option, but has anyone made a library for working with xsds specifically? ...

Scala equivalent of Ruby's map.each?

Very handy Ruby code: some_map.each do |key,value| # do something with key or value end Scala equivalent: someMap.foreach( entry => { val (key,value) = entry // do something with key or value }) Having to add the extra val line bugs me. I couldn't figure out how to state the function arg to extract the tuple, so I'm wonderin...

How to make Scala's immutable collections hold immutable objects.

I'm evaluating Scala and am having a problem with its immutable collections. I want to make immutable collections, which are completely immutable, right down through all the contained objects, the objects they reference, ad infinitum. Is there a simple way to do this? The code on http://www.finalcog.com/immutable-containers-scala il...

Scala collection type for filter

Assume you have a List(1,"1") it is typed List[Any], which is of course correct and expected. Now if I map the list like this scala> List(1, "1") map { | case x: Int => x | case y: String => y.toInt | } the resulting type is List[Int] which is expected as well. My question is if there is an equivalent to map for fil...

Do self: T => and this: T => have the same meaning when defining a trait?

It seems I can use self or this for referring to the mixed-in instance or rather to constraint the mixed-in instance. For instance, are those equivalent? scala> trait A { self: List[_] => } defined trait A scala> trait B { this: List[_] => } defined trait B Is this just a convention, or using something different than this provide som...

What’s the difference between ScalaTest and Scala Specs unit test frameworks?

Both are BDD (Behavior Driven Development) capable unit test frameworks for Scala written in Scala. And Specs is built upon may also involve the ScalaTest framework. But what does Specs offer ScalaTest doesn't? What are the differences? ...

Non deprecated way of appending an element to a List in Scala 2.7.5?

How do you add an element to a List in Scala 2.7.5, without creating a new List and without using a deprecated solution. ...

how to read immutable data structures from file in scala

I have a data structure made of Jobs each containing a set of Tasks. Both Job and Task data are defined in files like these: jobs.txt: JA JB JC tasks.txt: JB T2 JA T1 JC T1 JA T3 JA T2 JB T1 The process of creating objects is the following: - read each job, create it and store it by id - read task, retrieve job by id, create t...