scala

Why would I use Scala/Lift over Java/Spring?

Hi, I know this question is a bit open but I have been looking at Scala/Lift as an alternative to Java/Spring and I am wonder what are the real advantages that Scala/Lift has over it. From my perspective and experience, Java Annotations and Spring really minimizes the amount of coding that you have to do for an application. Does Scala/L...

Scala: "Parameter type in structural refinement may not refer to an abstract type defined outside that refinement"

Hi, I'm having a problem with scala generics. While the first function I defined here seems to be perfectly ok, the compiler complains about the second definition with: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement def >>[B](a: C[B])(implicit m: Monad[C]): C[B] = { ...

How can I use the Scala program schema2src?

This perhaps more a Server Fault question... I installed schema2src via sbaz and now I would like to convert a DTD (Apple's plist schema) to Scala source. $ schema2src usage: schema2src [flags] --module mname arg* or schema2src dtd arg* or (experimental) schema2src xsd arg* (this doesn't work at all yet) where supported [flag...

How to write two-dimensional array to xml in Scala 2.8.0

The following code (copied from a question from about a year ago) works fine under Scala 2.7.7, but does not behave correctly under Scala 2.8.0 (Beta 1, RC8). import scala.xml class Person(name : String, age : Int) { def toXml(): xml.Elem = <person><name>{ name }</name><age>{ age }</age></person> } def peopleToXml(people: ...

Lazy Quicksort in Scala

Is it possible to do this sort of thing in Scala? ...

Scala's simple-build-tool doesn't appear to run tests

I've used sbt to create a project, configured it thusly: val scalatest = "org.scala-tools.testing" % "scalatest" % "0.9.5" % "test" I then pasted the example from ScalaTest into a file and ran "sbt test" to see if it was working. The file compiles, but the test is never executed. As far as I can tell, this is as simple as it's meant ...

Scala: type variance and pattern matching between two equal types

I was playing around the other day with making a class to handle some arithmetic operations (yes, I know numeric is coming out in 2.8) and found myself wondering how to simplify the following: def Foo[A]( _1:A, _2:A ) = (_1, _2) match{ case _1:Bar, _2:Bar => _1 + _2 case _1:Baff, _2:Baff => _1 push _2 case _, _ => None } s...

ZeroC Ice "checked casts" in Scala

ZeroC Ice for Java translates every Slice interface Simple into (among other things) a proxy interface SimplePrx and a proxy SimplePrxHelper. If I have an ObjectPrx (the base interface for all proxies), I can check whether it actually has interface Simple by using a static method on SimplePrxHelper: val obj : Ice.ObjectPrx = ...; ...

What is meant by Scala's path-dependent types?

I've heard that Scala has path-dependent types. It's something to do with inner-classes but what does this actually mean and why do I care? ...

Scala and HttpClient: How do I resolve this error?

I'm using scala with Apache HttpClient, and working through examples. I'm getting the following error: /Users/benjaminmetz/IdeaProjects/JakartaCapOne/src/JakExamp.scala Error:Error:line (16)error: overloaded method value execute with alternatives (org.apache.http.HttpHost,org.apache.http.HttpRequest)org.apache.http.HttpResponse <a...

Using Sub-Types And Return Types in Scala to Process a Generic Object Into a Specific One

I think this is about covariance but I'm weak on the topic... I have a generic Event class used for things like database persistance, let's say like this: class Event( subject: Long, verb: String, directobject: Option[Long], indirectobject: Option[Long], timestamp: Long) { def getSubject = subject def getVerb = verb def...

Scala and Java BigDecimal

I want to switch from Java to a scripting language for the Math based modules in my app. This is due to the readability, and functional limitations of mathy Java. For e.g, in Java I have this: BigDecimal x = new BigDecimal("1.1"); BigDecimal y = new BigDecimal("1.1"); BigDecimal z = x.multiply(y.exp(new BigDecimal("2")); As you can s...

ORM supporting immutable classes

Which ORM supports a domain model of immutable types? I would like to write classes like the following (or the Scala equivalent): class A { private final C c; //not mutable A(B b) { //init c } A doSomething(B b) { // build a new A } } The ORM has to initialized the object with the constructor. So it is possible ...

Common idiom in Java to Scala, traverse/Iterate Java list into Scala list

I am processing a XML document and iterating through nodes. I want to iterate through the nodes and build a new List of some type. How would I do this with Scala: Here is my XML traverse code: def findClassRef(xmlNode: Elem) = { xmlNode\"classDef" foreach { (entry) => val name = entry \ "@name" val classid =...

Groovy as a substitute for Java when using BigDecimal?

I have just completed an evaluation of Java, Groovy and Scala. The factors I considered were: readability, precision The factors I would like to know: performance, ease of integration I needed a BigDecimal level of precision. Here are my results: Java void someOp() { BigDecimal del_theta_1 = toDec(6); BigDecimal del_theta_2...

Scala Array constructor?

scala> val a = Array [Double] (10) a: Array[Double] = Array(10.0) scala> val a = new Array [Double] (10) a: Array[Double] = Array(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) Why these two expressions have different semantics? ...

Good Scala slides and snippets?

I would like to do a presentation of Scala on my University in hope that I can get some attention for this great language. I would like to show some slides and then do some real-time codding. I think I will use IDEA IDE to further show how easy it is to use. What I need are good slides (to lazy to do them myself). Neat examples of code...

Are Scala "continuations" just a funky syntax for defining and using Callback Functions?

And I mean that in the same sense that a C/Java for is just a funky syntax for a while loop. I still remember when first learning about the for loop in C, the mental effort that had to go into understanding the execution sequence of the three control expressions relative to the loop statement. Seems to me the same sort of effort has to ...

Is there a PHP benchmark that meets these specific criteria?

The actual question at the bottom... first some background info: I'm working on a tool which converts PHP code to Scala. As one of the finishing touches, I'm in need of a really good (er, somewhat biased) benchmark. By dumb luck my first benchmark attempt was with some code which uses bcmath extensively, which unfortunately is 1000x sl...

calling multiple functions with same instance in scala

is there any way I can achieve the following in scala with new Car() { examineColor bargain(300) buy } instead of val c = new Car() c.examineColor c.bargain(300) c.buy ...