scala-2.8

Translate Java class with static attributes and Annotation to Scala equivalent

I'm currently trying to "translate" the following Java class to an equivalent Scala class. It's part of a JavaEE6-application and i need it to use the JPA2 MetaModel. import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.StaticMetamodel; @StaticMetamodel(Person.class) public class Person_ { public s...

Scala's sealed abstract.

What is the difference between sealed abstract and abstract Scala class? ...

How can I extend Scala collections with an argmax method?

I would like to add to all collections where it makes sense, an argMax method. How to do it? Use implicits? ...

Scala method where type of second parameter equals part of generic type from first parameter

I want to create a specific generic method in Scala. It takes two parameters. The first is of the type of a generic Java Interface (it's from the JPA criteria query). It currently looks like this: def genericFind(attribute:SingularAttribute[Person, _], value:Object) { ... } // The Java Interface which is the type of the first paramet...

What Is the Concept of "Weak Conformance" in Scala?

I just recently encountered the term "Weak Conformance" (in retronym's answer to How to set up implicit conversion to allow arithmetic between numeric types?). What is it? ...

is the case of scala function parameters relevant?

Hi all, regarding the following scala code, functions m2a and m2b apparently differ only by the case of the parameter, ie abc vs Abc. This seems to make some difference in the result as per example below. When running it with a recent 2.8 compiler, it results in the following (I would have expected all true). Any insights would be apprec...

Different output of matching on sequence in Scala 2.8

I'm a newbie to scala. I'm trying an example from the book "Programming Scala". The example can be get from here The output under Scala 2.8 RC6: List: List: List: I got the expected result under Scala 2.7.7: List: 1 3 23 90 List: 4 18 52 List: I don't know why it doesn't work on Scala 2.8. Please help me to figure it out. ...

When is a return type required for methods in Scala?

The Scala compiler can often infer return types for methods, but there are some circumstances where it's required to specify the return type. Recursive methods, for example, require a return type to be specified. I notice that sometimes I get the error message "overloaded method (methodname) requires return type", but it's not a general...

In Scala, how would I give a Singleton a constructor?

My design incorporates a small database abstraction, whereby I implement each database as a Singleton (well, an object), with custom methods on the database for the couple of operations the code calls (it's mainly a log parser, dumping interesting statistics to a database). I'd like to construct the Singleton database classes if possibl...

Scala 2.8.0 toolchain

I've currently spent the best part of my day grappling with dependency hell; something I haven't really experienced in a while. I'm attempting to use Scala 2.8.0 as per the answers to this question, and the fact that I intend to use Actors - for which the fork/join pool seems to be faster (according to community buzz, anyhow). The prob...

infer a common supertype based on a parameter value and function parameter types

Should the following be compiled without needing an explicit type definition on this? def prepList[B >: A](prefix: PlayList[B]) : PlayList[B] = prefix.foldr(this: PlayList[B])((node, suffix) => suffix.prepNode(node)) It seems to me that the type should be able to inferred. Is this just a limitation in the Scala compiler, or is there...

HowTo get the class of _ :Any

I've wrapped a Message and would like to log which message I've wrapped. val any :Any = msg.wrappedMsg var result :Class[_] = null The only solution I could find is matching everything: result = any match { case x:AnyRef => x.getClass case _:Double => classOf[Double] case _:Float => classOf[Float] case _:Long => classOf[Lo...

In Scala, how can a constructor refer to the object it is creating?

I want to implement a prototype-based system in Scala. At the root of the type hierarchy is the ROOT node, which has a prototype that refers to itself. The following code demonstrates what I'm trying to do: class Node(val prototype: Node) { private def this() = this(this) } object Node { val ROOT = new Node } Unfortunately, ...

Converting immutable to mutable collections

What is the best way to convert collection.immutable.Set to collection.mutable.Set? ...

how to install squeryl for scala in ellipse?

I want to run squeryl for PostgreSQL on scala in ellipse. But I have no idea how will do it. I tried to see on the site http://squeryl.org but there is no mention of the steps needed. Only the list of neccessary files is given. can anybody guide me step-by-step to run squeryl for scala in ellipse. I am running scala 2.8.0 ...

Iterating circular way

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? ...

actors with daemon-style semantics

Scala 2.8 was announced yesterday. They highlight among other things "Enhanced actors". What does "actors with daemon-style semantics" mean and where can I find more about that? ...

RemoteActor unregister actor

I'm playing with RemoteActors. Now I wonder, what happens if I shut down an RemoteActor. The actor was made available with RemoteActor.alive and RemoteActor.register. I can't find the inverse of either of both: alive and register. How do I properly shut down an RemoteActor? Update To make it more obvious, I made a 'small' example. Ne...

Scala 2.8 and Map views

In 2.7 I could do the following: val lazyM: Map[_, _] = map.projection.mapElements(v => expCalc(v)) //MAP VIEW I can't find a way of doing this in 2.8 and actually ending up with a map: val m: Map[_, _] = map.view.map(kv => kv._1 -> expCalc(kv._2)).toMap //STRICT This seems like a significant loss of functionality and therefore I a...

Scala implementation of C#-like yield with "for"

I'm trying to use various scala implementations of C#-like yield return (i.e. link text) with "for" -constructions such as: private def permutations[T](s: Vector[T]) = { def swap(i: Int, j: Int) { val tmp = s(i) s.set(i, s.get(j)) s.set(j, tmp) } iterator[Vector[T]] { def generate(left: Int, right: Int): Unit @cps...