scala

Are there scala-like mixins for C++?

Scala Mixins ...

Factory methods for implementations of Java interfaces wrapped with Scala implicits?

I'm using Scala implicits to define a rich wrapper for a Java interface: class RichThing { def richStuff: Unit = {} } In the companion object I define the implicit conversion and an apply factory method: object RichThing { implicit def rich( thing: JavaThing ) = new RichThing() def apply() = new RichThing() } With this, I...

EBNF to Scala parser combinator

I have the following EBNF that I want to parse: PostfixExp -> PrimaryExp ( "[" Exp "]" | . id "(" ExpList ")" | . length )* And this is what I got: def postfixExp: Parser[Expression] = ( primaryExp ~ rep( "[" ~ expression ~ "]" | "." ~ ident ~"...

Creating a parametric graph type in Scala

I'd like to create a generic type hierarchy for representing graphs. In particular, I'd like like to have classes Graph and Node, and I want that for every Graph type, there is a corresponding Node type and if I create a generic function for manipulating Graphs, I want this function to use the actual Node type. An example that I tried t...

Scala remote actors

Are there any guides or tutorials which explain the possibility to use scala actors remotely? All I have found until now is one example (without comments) but that's hardly enough. ...

Is anyone using Scala in anger (and what advice for a Java programmer)?

I've been a Java programmer for over 10 years since starting off with Smalltalk. It's my opinion that next big languages are likely to be ones which run on the ubiquitous Java Virtual Machine. I'd like to take advantages of some of the features that Scala (among other languages) has - case statements for class hierarchies, closures, type...

Does Scala's pattern matching violate the Open/Closed Principle?

If I add a new case class, does that mean I need to search through all of the pattern matching code and find out where the new class needs to be handled? I've been learning the language recently, and as I read about some of the arguments for and against pattern matching, I've been confused about where it should be used. See the followi...

Design patterns for Agent / Actor based concurrent design.

Recently i have been getting into alternative languages that support an actor/agent/shared nothing architecture - ie. scala, clojure etc (clojure also supports shared state). So far most of the documentation that I have read focus around the intro level. What I am looking for is more advanced documentation along the gang of four but in...

Unpacking tuple types in Scala

I was just wondering, can I decompose a tuple type into its components' types in Scala? I mean, something like this trait Container { type Element } trait AssociativeContainer extends Container { type Element <: (Unit, Unit) def get(x : Element#First) : Element#Second } ...

Scala: splitting a list using a predicate for sublists

I just had a use case where I needed to split a list into n sublists, so that elements are taken in order from the original list and grouped while the predicate is true for the sublist (when it is false, a new sublist is started). I didn't find this functionality in the standard library, and I thought it was a good exercise to try to sol...

How does the "specs" BDD framework for Scala work?

I'm just getting started with Scala, and I'm wondering which language feature allows you to do this: "PersistentQueue" should { "add and remove one item" in { withTempFolder { val q = new PersistentQueue(folderName, "work", Config.fromMap(Map.empty)) q.setup q.length mustEqual 0 q.totalItems mustEqual 0 ...

Type parameters versus member types in Scala

I'd like to know how do the member types work in Scala, and how should I associate types. One approach is to make the associated type a type parameter. The advantages of this approach is that I can prescribe the variance of the type, and I can be sure that a subtype doesn't change the type. The disadvantages are, that I cannot infer the...

What is the rationale behind having companion objects in Scala?

I am new to Scala and may be missing something very basic but I couldn't think of a case where a companion object (singleton) for a class is needed. Why would I want to create a class, say Foo and also create a companion object for it. Can anyone please explain ? ...

Do you plan to use the Scala programming language and on what project?

Where do you seen using Scala for your project? ...

why is the lift web framework scalable?

I want to know the technical reasons why the lift webframework has high performance and scalability? I know it uses scala, which has an actor library, but according to the install instructions it default configuration is with jetty. So does it use the actor library to scale? Now is the scalability built right out of the box. Just add ...

Generic wildcards in variable declarations in Scala

In Java I might do this: class MyClass { private List<? extends MyInterface> list; public void setList(List<MyImpl> l) { list = l; } } ...assuming that (MyImpl implements MyInterface) of course. What is the analog for this in Scala, when using a Buffer? import java.lang.reflect._ import scala.collection.mutable._ class Sca...

Scala covariance / contravariance question

Following on from this question, can someone explain the following in Scala: class Slot[+T] (var some: T) { // DOES NOT COMPILE // "COVARIANT parameter in CONTRAVARIANT position" } I understand the distinction between T+ and T in the type declaration (it compiles if I use T). But then how does one actually write a class whi...

scala turning an Iterator[Option[T]] into an Iterator[T]

I have an Iterator[Option[T]] and I want to get an Iterator[T] for those Options where T isDefined. There must be a better way than this: it filter { _ isDefined} map { _ get } I would have thought that it was possible in one construct... Anybody any ideas? ...

Scala and interfaces

In Java I would typically declare my entire domain as interfaces, possibly with some kind of Factory to get me implementations. This is partly because I am so old I can remember when some persistence layers required implementation classes to subclass a specific class but also so that I can easily: mock objects for testing purposes prox...

Scala equivalent of new HashSet(Collection)

What is the equivalent Scala constructor (to create an immutable HashSet) to the Java: new HashSet<T>(c) where c is of type Collection<? extends T>. All I can find in the HashSet Object is apply ...