scala

Scala immutable objects and traits with val fields

Hi all, I would like to construct my domain model using immutable objects only. But I also want to use traits with val fields and move some functionality to traits. Please look at the following example: trait Versionable { val version = 0 def incrementVersion = copy(version=version+1) } Unfortunatelly such code doesn't work - copy ...

Binary search implementation with actors in scala?

Hi, So I have such problem in Scala, I need to implement binary search with the help of actors, with no loops and recursion, preferably with concurrency between actors. Of course it has no sense, but the problem is as follows. I think that it will be nice to have one actor-coordinator,which coordinates the work of others. So input data ...

How do I specify a type bound for Float and Double on a generic type in Scala?

I am writing some simple Vector and Matrix classes. They look like this: // Vector with Floats case class Vector3f(x: Float, y: Float, z: Float) { def +(v: Vector3f) = Vector3f(x + v.x, y + v.y, z + v.z) } // Vector with Doubles case class Vector3d(x: Double, y: Double, z: Double) { def +(v: Vector3d) = Vector3d(x + v.x, y + v.y, ...

Dependency injection, Scala and Spring

I love the concept of DI and loosely coupled system, a lot. However, I found tooling in Spring lacking at best. For example, it's hard to do "refactoring", e.g. to change a name of a bean declared in Spring. I'm new to Spring, so I would be missing something. There is no compiling time check etc. My question is why do we want to use XM...

Numerical computing environment on cloud? [ Undergrad Project ]

Hello all. I am a computer science undergraduate currently in my final year. As my final year project, I am thinking of creating a matlab-like numerical computing environment as SAAS that supports matrix manipulations, plotting of functions and data, image processing operations etc. The project is going to be created in Java + Scala. S...

liftweb: getting model field

Hello. I am new with liftweb and scala. I am developing json-rest api for rss agregator and I have two problems: package my.domain import net.liftweb.http._ import net.liftweb.http.rest._ import net.liftweb.json.JsonAST._ import net.liftweb.common.{Box,Full,Empty,Failure,ParamFailure} import my.domain.model.{RssItem} object ContentR...

liftweb mapper - setting table name in lower case

Is it possible to force liftweb mapper use table name in lower case for querying models? ...

Are recursive structural types not supported in scala anymore?

Some people claim that scala is able to deal with recursive structural types if you use the -Yrecursion option of scalac. Nevertheless my minimalistic example does not compile: type Num = { def +(n: Num): Num } Compilation yields: $ scalac -version Scala compiler version 2.8.0.final -- Copyright 2002-2010, LAMP/EPFL $ scalac -Yrecu...

Scala socket cannot write to output stream

Hi, I'm new in the scala world, so excuse my trivial question. :) I just want to open a socket to a port and sand and receive messages. If I receive a HELO, I want to react with a message, but I'm not able to write to the socket in any way. I used nc to listen for incoming connections: nc -k -l 127.0.0.1 3333 When the client is conne...

Generalized structural type conformance in Scala

I'm interested in the problem of conforming a specific type to a more general structural type. Consider the following examples: trait Sup trait Sub extends Sup type General = { def contra(o: Sub): Unit def co(): Sup def defaults(age: Int): Unit def defaults2(age: Int): Unit def defaults3(first: String): Unit } trait ...

Extending built-in collections, issues with built-in methods

I am a Scala novice so forgive me if this is a stupid question, but here goes... Imagine I wish to create an extended Map type that includes additional methods. I can see a few ways to do this. The first would be with composition: class Path[V](val m: Map[V, Int]) { // Define my methods } Another would be via inheritance, e.g. c...

Array-Languages like Code Reuse in Scala

Array programming languages (also known as vector or multidimensional languages) generalize operations on scalars to apply transparently to vectors, matrices, and higher dimensional arrays. Is it possible to achieve this kind of code reuse in Scala? ...

Proxies / delegates in Scala

I've seen several Scala questions recently (e.g. here, here, and here) that called for the use of proxies, and it's come up more than once in my own work. The Scala library has a number of proxy traits (14, if I counted correctly). Proxy classes/traits usually contain lots of boilerplate: class FooProxy(val self: Foo) extends Foo { ...

About Scala generics: cannot find class manifest for element type T

For a function as below: def reverse[T](a: Array[T]): Array[T] = { val b = new Array[T](a.length) for (i <- 0 until a.length) b(i) = a(a.length -i - 1) b } I am getting "error: cannot find class manifest for element type T" from line 2. Is there anyway to solve this? ...

How to pattern match large Scala case classes?

Consider the following Scala case class: case class WideLoad(a: String, b: Int, c: Float, d: ActorRef, e: Date) Pattern matching allows me to extract one field and discard others, like so: someVal match { case WideLoad(_, _, _, d, _) => d ! SomeMessage(...) } What I would like to do, and what's more relevant when a case class h...

liftweb - accessing get/post parameters

How is it possible to simply access to get and post attributes in lift framework inside RestHelper? There are no any explicit examples about it in documentation :( package my.domain import net.liftweb.http._ import net.liftweb.http.rest._ import net.liftweb.json.JsonAST._ import net.liftweb.json._ import net.liftweb.common.{Box,Full,Em...

Library to Integrate Facebook login with Play Framework?

I'm learning using Play Framework and doing a demo app for it. For this app I want also to integrate with the Facebook API, allowing users to log using Facebook Ids. Knowing that Play is a stateless framework and the way it works, there is some library or module recommended? I've not been able to find any but I ask just in case. ...

Scala: Using StandardTokenParser for parsing hexadecimal numbers

I am using Scala combinatorial parser by extending scala.util.parsing.combinator.syntactical.StandardTokenParser. This class provides following methods def ident : Parser[String] for parsing identifiers and def numericLit : Parser[String] for parsing a number (decimal I suppose) I am using scala.util.parsing.combinator.lexical.Scanner...

NodeSeq match fails, but equivalent Elem match succeeds -- why? how to fix?

OK, this is stumping both me (rookie at Scala) as well as my colleague (more advanced at Scala). Scala 2.8.0. Here's a demonstration of the problem: // I've got a var with some XML in it scala> qq2 res9: scala.xml.Elem = <a><a1>A1</a1><bs><b>B1</b><c>C1</c><d>D1</d></bs></a> // I can extract sub-elements scala> (qq2 \ "bs") res10: scal...

Ordered ListSet

ListSet (collection.immutable.ListSet) is a inverse ordered set. I need ordered set. This is a example of original ListSet: var a = ListSet(1,2,3) var ite = a.iterator ite.next // returns 3 ite.next // returns 2 ite.next // returns 1 And this is a example of I need: var a = ListSet(1,2,3) var ite = a.iterator ite.next // returns 1 it...