Great JVM news

April 8th, 2009

 The Google AppEngine opens up for Java. Python is a great language, but still a nice-language (compared to Java). A light-weight alternative to host Jav-applications in the cloud.

What some might have guessed is now official?: Twitter is doing its heavy lifting with Scala We don’t have to feel bad anymore to do write statically typed code:-)

Apply on Tuples

June 10th, 2007

After playing with implicit anon function I came up with the following useful extension to Tuple, here the new method for Tuple2 :

def apply[R] (fn : Function2[T1,T2,R]) = fn(_1,_2);

This allows the following to write very easily:

def add(a: Int, b:Int) = a+b;

val a = 1::2::3::Nil
// calling binary functions with implicit parameter of Tuple is not possible
val li246 = (a zip a){_(add)}
//nested implicit parameter - acts like an explode on Tuple
val liSquared = (a zip a){_{_*_} }

Perhaps this is best implemented on the Product traits.

What bothers me a bit is that there are now two equivalent ways of adding

(2,2)(add) and add(2,2)

Anyway, I think having a tuple and calling a function with this as parameter list is quite a common idiom. Really nice if this would also work for currying, have to check this

Why not adding this to Function2? I thought about (and tried it) and then decided otherwise:

  1. It would weaken the typing, afterward it would be impossible for the compiler to tell if I was calling a Function1[Tuple2,R] or the Function2[T1,T2,R]
  2. It gets very confusing for the parser, especially with the new uses of ‘_’ for impartial function evals and implicit args

Java-generics in Scala

April 6th, 2007

Something I overlooked in the tool-docs and complained about:

Use generic Java types.

This makes the following possible:

implicit def JavaCollectionToList[T>:Null<:Object] (coll: java.util.Collection[T]) : List[T] = {



implicit def JavaIteratorToScalaList[T>:Null<:Object](it: java.util.Iterator[T]):List[T]={

it.hasNext match{

case true=> val head = it.next(); head :: JavaIteratorToScalaList(it);
case false=> Nil;



With these coercions a List[String] can be assigned from a java.util.Collection<String>

Open question: How will this work with .NET generics (not an issue for me at the moment and the IL-code generation seems to have a problem)