scala-2.8

How to create and use a multi-dimensional Array in Scala 2.8

Hello everyone, in Scala 2.8 how do I create an array of multiple dimensions? For example I want an integer or double matrix, something like double[][] in java. I know for a fact that arrays have changed in 2.8 and that the old arrays are deprecated, but are there multiple ways to do it now and if yes, which is best? Hoping for quick ...

Overload constructor for Scala's Case Classes?

In Scala 2.8 is there a way to overload constructors of a case class? If yes, please put a snippet to explain, if not, please explain why? ...

Generic object load function for scala

I'm starting on a Scala application which uses Hibernate (JPA) on the back end. In order to load an object, I use this line of code: val addr = s.load(classOf[Address], addr_id).asInstanceOf[Address]; Needless to say, that's a little painful. I wrote a helper class which looks like this: import org.hibernate.Session class DataLoader...

Don't understand the typing of Scala's delimited continuations (A @cps[B,C])

I'm struggling to understand what precisely does it mean when a value has type A @cps[B,C] and what types of this form should I assign to my values when using the delimited continuations facility. I've looked at some sources: http://lamp.epfl.ch/~rompf/continuations-icfp09.pdf http://www.scala-lang.org/node/2096 http://dcsobral.blogs...

scala 2.8 implict java collections conversions

I have problem with JavaConversions with 2.8 beta: import scala.collection.JavaConversions._ class Utils(dbFile : File, sep: String) extends IUtils { (...) def getFeatures() : java.util.List[String] = csv.attributes.toList } And then exception: [INFO] Utils.scala:20: error: type mismatch; [INFO] found : List[String] [IN...

How to split and dispatch an async control-flow using Continuations?

Hello, I have an asynchronous control-flow like the following: ActorA ! DoA(dataA, callback1, callbackOnErrorA) def callback1() = { ... ActorB ! DoB(dataB, callback2, callbackOnErrorB) } def callback2() = { ActorC ! DoC(dataC, callback3, callbackOnErrorC) } ... How would I divide this flow into several parts (continuations)...

How do I specify a static array in a Scala 2.8 annotation?

I've been building out some annotated domain classes in Scala 2.8.0 using Hibernate Annotations 3.4.0. It's been working fine, except that there are certain annotations which take an array as a parameter. For example, here's a Java annotation that I want to express in Scala: @OneToMany(mappedBy="passport_id", cascade=CascadeType.PERSIST...

Cost of using repeated parameters

I consider refactoring few method signatures that currently take parameter of type List or Set of concrete classes --List[Foo]-- to use repeated parameters instead: Foo*. Update: Following reasoning is flawed, move along... This would allow me to use the same method name and overload it based on the parameter type. This was not po...

When is @uncheckedVariance needed in Scala, and why is it used in GenericTraversableTemplate?

@uncheckedVariance can be used to bridge the gap between Scala's declaration site variance annotations and Java's invariant generics. scala> import java.util.Comparator import java.util.Comparator scala> trait Foo[T] extends Comparator[T] defined trait Foo scala> trait Foo[-T] extends Comparator[T] <console>:5: error: contrav...

Scala version of Rubys' each_slice?

Does Scala have a version of Rubys' each_slice from the Array class? ...

Scala: Matching optional Regular Expression groups

I'm trying to match on an option group in Scala 2.8 (beta 1) with the following code: import scala.xml._ val StatementPattern = """([\w\.]+)\s*:\s*([+-])?(\d+)""".r def buildProperty(input: String): Node = input match { case StatementPattern(name, value) => <propertyWithoutSign /> case StatementPattern(name, sign, value) => <p...

How do I create an XML root node in Scala without a literal element name?

I'm looking to create a document like this: <root/> That I can add children to programatically. Theoretically, it would look like this: val root_node_name = "root" val doc = <{root_node_name}/> But that doesn't seem to work: error: not found: value < So, what I tried instead was this: val root_node_name = "root" val doc = new s...

Scala 2.8 Actors

Hi, We're looking at using actors in our Scala code quite soon. We're also thinking of moving to Scala 2.8 in the next few weeks. We've been keeping an eye on Akka but it doesn't currently support 2.8 and plans for it have slipped from the 0.7 release to 0.8 We would like distributed, supervised actors. Is there an alternative to Akka?...

What is the proper way to remove elements from a scala mutable map using a predicate

How to do that without creating any new collections? Is there something better than this? val m = scala.collection.mutable.Map[String, Long]("1" -> 1, "2" -> 2, "3" -> 3, "4" -> 4) m.foreach(t => if (t._2 % 2 == 0) m.remove(t._1)) println(m) P.S. in Scala 2.8 ...

maven and lift using scala 2.8 : lift-mapper missing?

Newbie question since I'm not up to speed using maven at all. I'm trying to use scala + lift using scala 2.8, environment is a win7 box if that matters. I create a basic project using: mvn archetype:generate -U -DarchetypeGroupId=net.liftweb -DarchetypeArtifactId=lift-archetype-basic -DarchetypeVersion=2.0-scala280-SNAPSHOT -Da...

How do I implement a collection in Scala 2.8?

In trying to write an API I'm struggling with Scala's collections in 2.8(.0-beta1). Basically what I need is to write something that: adds functionality to immutable sets of a certain type where all methods like filter and map return a collection of the same type without having to override everything (which is why I went for 2.8 in th...

Function syntax puzzler in scalaz

Following watching Nick Partidge's presentation on deriving scalaz, I got to looking at this example, which is just awesome: import scalaz._ import Scalaz._ def even(x: Int) : Validation[NonEmptyList[String], Int] = if (x % 2 ==0) x.success else "not even: %d".format(x).wrapNel.fail println( even(3) <|*|> even(5) ) //prints: Failu...

Scalaz Kleisli question

There is a trait called Kleisli in the scalaz library. Looking at the code: import scalaz._ import Scalaz._ type StringPair = (String, String) val f: Int => List[String] = (i: Int) => List((i |+| 1).toString, (i |+| 2).toString) val g: String => List[StringPair] = (s: String) => List("X" -> s, s -> "Y") val k = kleisli(f) >=> k...

Scalaz: request for use case for Cokleisli composition

This question isn't meant as flame-bait! As it might be apparent, I've been looking at Scalaz recently. I'm trying to understand why I need some of the functionality that the library provides. Here's something: import scalaz._ import Scalaz._ type NEL[A] = NonEmptyList[A] val NEL = NonEmptyList I put some println statements in my func...

short way to breakOut to specific collection type?

scala> val m = Map(1 -> 2) m: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala> m.map{case (a, b) => (a+ 1, a+2, a+3)} res42: scala.collection.immutable.Iterable[(Int, Int, Int)] = List((2,3,4)) What I want is for the result type to be List[(Int, Int, Int)]. The only way I found is: scala> m.map{case (a, b) => (a+ 1, a+2...