scala

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

Strange Scala error.

I tried to create abstract turn based Game and abstract AI: abstract class AGame { type Player type Move // Player inside def actPlayer : Player def moves (player : Player) : Iterator[Move] def play (move : Move) def undo () def isFinished : Boolean def result (player : Player) : Double } abstract class Ai[Game <: ...

Odd behaviour with scala method syntax

Hi chaps, I hit a bit of a quirk of scala's syntax I don't really understand object Board { def getObjectAt(x:Int, y:Int):Placeable = return locations(x)(y) } works fine. But object Board { def getObjectAt(x:Int, y:Int):Placeable { return locations(x)(y) } } returns the error Board.scala:8: error: illegal start of d...

Parser that accepts Scala Identifiers?

I was wondering whether the standard Scala parser combinators contain a parser that accepts the same identifiers that the Scala language itself also accepts (as specified in the Scala Language Specification, Section 1.1). The StdTokenParsers trait has an ident parser, but it rejects identifiers like empty_?. (If there is indeed no such...

What can I do with Virtual Classes?

I've seen (and heard) quite a bit of noise about adding virtual classes to Scala (it already has virtual types, according to Martin Odersky). Could someone provide a layman's perspective (perhaps with an example) on what a virtual type is and what could be possible were scala to have virtual classes? [I have no experience with C or C++...

How Does One Make Scala Control Abstraction in Repeat Until?

Hi I am Peter Pilgrim. I watched Martin Odersky create a control abstraction in Scala. However I can not yet seem to repeat it inside IntelliJ IDEA 9. Is it the IDE? package demo class Control { def repeatLoop ( body: => Unit ) = new Until( body ) class Until( body: => Unit ) { def until( cond: => Boolean ) { body; ...

How do I call a Scala Object method using reflection ?

say, I have the following: trait SomeTrait { def someMethod: String; } object SomeObject extends SomeTrait { def someMethod = "something"; } I would like to call "someMethod" using reflection as I have the object name as a String. Something like: val objectName = "SomeObject" val someTrait:SomeTrait = ???.asInstanceOf[SomeTr...

Automatic performance testing of Scala libraries

Do any Scala testing libraries help with performance tests? Can't find anything relevant in ScalaTest or specs. ...

Is there a Scala version of .irbrc or another way to define some default libraries for REPL use?

I've written a little library that uses implicits to add functionality that one only needs when using the REPL in Scala. Ruby has libraries like this - for things like pretty printing, firing up text editors (like the interactive_editor gem which invokes Vim from irb - see this post), debuggers and the like. The library I am trying to wr...

What's the (hidden) cost of lazy val? (Scala)

One handy feature of Scala is lazy val, where the evaluation of a val is delayed until it's necessary (at first access). Ofcourse a lazy val must have some overhead - somewhere Scala must keep track of whether the value has already been evaluated and the evaluation must be synchronized, because multiple threads might try to access the v...

Compatibility between Scala closures and Java 8 closures

After reading some OpenJDK mailinglist entries, it seems that the Oracle developers are currently further removing things from the closure proposal, because earlier design mistakes in the Java language complicate the introduction of the Java closures. Considering that Scala closures are much more powerful than the closures planned for J...

How to specialize a type parameterized argument to multiple different types for in Scala?

I need a back-check (please). In an article ( http://www.win-vector.com/blog/2010/06/automatic-differentiation-with-scala/ ) I just wrote I stated that it is my belief in Scala that you can not specify a function that takes an argument that is itself a function with an unbound type parameter. I have edited this question to try and si...

NoMethod error from scala loop

Hi, I have a pair of loops over a nested array object in scala def populateBoard(data:Array[Array[Char]]) { Board.resize(data(0).length, data.length) for(y <- 0 to data.length-1) { val row = data(y) for(x <- 0 to row.length-1) { Board.putObjectAt(x,y,GamePieceFactory.createInstance(row(x),x,y)) ...

Why do case class companion objects extend FunctionN?

When you create a case class, the compiler creates a corresponding companion object with a few of the case class goodies: an apply factory method matching the primary constructor, equals, hashCode, and copy. Somewhat oddly, this generated object extends FunctionN. scala> case class A(a: Int) defined cla...

Scala match question

Hello to everyone. I came across with an error on my Scala code that I cannot solve by myself (I am new at Scala). I have the following code: def myFunction(list: List[Any]): String = { var strItems : String = ""; list.foreach(item => { strItems += item match { case x:JsonSerializable => x.toJson() case y:String => (...

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 capture group using regex

Let's say I have this code: val string = "one493two483three" val pattern = """two(\d+)three""".r pattern.findAllIn(string).foreach(println) I expected findAllIn to only return 483, but instead, it returned two483three. I know I could use unapply to extract only that part, but I'd have to have a pattern for the entire string, something...

varargs parameter as type parameter?

Is there any way to create something similar to this: class F[A] {def apply(a: A) = println(a)} So that I can: (new F[Int*])(1,2,3) UPDATE: but otherwise, I want F to accept normal parameters: (new F[Int])(1) ...

Can ScalaCheck/Specs warnings safely be ignored when using SBT with ScalaTest?

I have a simple FunSuite-based ScalaTest: package pdbartlett.hello_sbt import org.scalatest.FunSuite class SanityTest extends FunSuite { ...