scala

Creating two different types of Users (Scala, Lift)

Hi all- I am creating a website which will need two types of users: students and providers. In a traditional java setting I would create a user class (or interface) and then create two classes which inherited from the user. Is this the best course in scala too, using the "extends" and "with" modifiers? If that is indeed the best way ...

Error-tolerant XML parsing in Scala

I would like to be able to parse XML that isn't necessarily well-formed. I'd be looking for a fuzzy rather than a strict parser, able to recover from badly nested tags, for example. I could write my own but it's worth asking here first. Update: What I'm trying to do is extract links and other info from HTML. In the case of well-formed ...

Is there any Non-blocking IO open source implementation for Scala's actors?

I have quite large files that I need to deal with (500Meg+ zip files). Are there any non-blocking IO open source implementations for Scala's actors? ...

Overriding equals and hashCode methods for a JavaBeans implemented in Scala

Hello, I'm working on a project using iBatis and a Java caching tool ehcache but I'm implementing the model classes in Scala. I'm having a stong feeling that I'll have to override the equals and hashCode methods to enable the cache easily manage objects on it. Since most of the required properties in the scala classes are vars, I need ...

What are Scala continuations and why use them?

So I just finished "Programming in Scala" and I've been looking into the changes between Scala 2.7 and 2.8. The one that seems to be the most important is the continuations plugin but I don't understand what its useful for or how it works. I've seen that 'its good for async I/O' but I haven't been able to find out why. Some of the mor...

In scala, how would you declare static data inside a function?

In many situations I find that I need to create long-living values inside a function's scope, and there is no need for this data to be at class/object scope. For example, object Example { def activeUsers = { val users = getUsersFromDB // connects to the DB and runs a query users.filter(_.active) } } Abov...

Writing a time function in Haskell

I'm new to Haskell and I'd like to be able to time the runtime of a given function call or snippet of code. In Clojure I can use 'time': user=> (time (apply * (range 2 10000))) "Elapsed time: 289.795 msecs" 2846259680917054518906413212119868890148051... In Scala, I can define the function myself: scala> def time[T](code : => T) = {...

What is the current state of the Scala Eclipse plugin?

Is the current Scala Eclipse plugin (http://www.scala-lang.org/node/94) usable? I keep reading that its unstable and buggy, even unusable. See previous thread: http://stackoverflow.com/questions/796258/what-is-the-current-state-of-tooling-for-scala I've tried it out briefly but only for trivial programs, so far it seems fine. Thanks! ...

Scala extra parentheses printout

Hi, I wrote my first sample scala program and it looks like this: def main(args: Array[String]) { def f1 = println("aprintln") println("applying f1") println((f1 _).apply) println("done applying f1") } The output is applying f1 aprintln () done applying f1 Can someone explain why the extra () appears? I thought j...

Java <-> Scala interop: transparent List and Map conversion

I am learning Scala and I have a Java project to migrate to Scala. I want to migrate it by rewriting classes one-by-one and checking that new class didn't break the project. This Java project uses lots of java.util.List and java.util.Map. In new Scala classes I would like to use Scala’s List and Map to have good-looking Scala code. The...

scala case classes questions

Hi, I have two questions regarding the '::' case class. :: can be used as case head :: tail => ... How does it work? Meaning, what is exactly the flow that Scala uses to match a List instance with the :: case class? Given that I have a class MyClass, with operator op, can I create a case class named op that I can use as: case foo o...

Library support for Scala's NotNull trait

As far as I understand, if you want a reference type to be non-nullable you have to mixin the magic NotNull trait, and the compiler will automatically prevent you from putting null-able values in it. See this mailing-list thread for instance. What lacking is, a decent library support for non-nullable types. If I would like to write a pa...

When is Scala 2.8.0 going to be released?

Or a release candidate? My google-fu fails me. ...

"dangling" local blocks in scala

In scala it is possible to define a local block in a function. The local block evaluates to the last statements, for example, val x = {val x =1;x+1} Here x==2, the inner val x is local to that block. However those local blocks can cause sneaky bugs when writing anonymous classes. For example (from scala's reference) new Iterator[Int...

When are threads created for scala actors

After reading about using react in an actor, I thought reacts would share the same thread when there weren't multiple reacts pending, but it isn't the case: import scala.actors.Actor import scala.actors.Actor._ class SleepyReactor extends Actor { def act() { loop { react { case x => { println("reacting to...

Netbeans scala plugin - no documentation

I have installed Netbeans 6.7.1 with Scala plugin as described here. I got my "Hello World" project to compile and run. The problem I have now is that there is no documentation available for Scala functions and classes, all I get is No document found. In the Scala Platform Manager I have both sources and javadoc not empty and directori...

Difference between Iterator and Stream in Scala?

It seems that both of these are lazy and allow you to keep returning elements to your heart's content. What's the difference between the two? ...

Can I run JUnit 4 to test Scala code from the command line?

If so, how? I haven't come across the proper incantation yet. If not, what's the best approach to unit-testing Scala code from the command line? (I'm a troglodyte; I use IDEs when I have to, but I prefer to play around using Emacs and command-line tools.) ...

parser combinator: how to terminate repetition on keyword

I'm trying to figure out how to terminate a repetition of words using a keyword. An example: class CAQueryLanguage extends JavaTokenParsers { def expression = ("START" ~ words ~ "END") ^^ { x => println("expression: " + x); x } def words = rep(word) ^^ { x => println("words: " + x) x } ...

How to split a Scala script into multiple files

Used as a scripting language, does Scala have some sort of include directive, or is there a way to launch a script from an other script ? ...