scala

Scala versus F# question: how do they unify OO and FP paradigms?

What are the key differences between the approaches taken by Scala and F# to unify OO and FP paradigms? EDIT What are the relative merits and demerits of each approach? If, in spite of the support for subtyping, F# can infer the types of function arguments then why can't Scala? ...

Different Scala Actor Implementations Overview

I'm trying to find the 'right' actor implementation for my thesis. I realized there is a bunch of them and it's a bit confusing to pick one. Personally I'm especially interested in remote actors, but I guess a complete overview would be helpful to many others. This is a pretty general question, so feel free to answer just for the impleme...

How to further improve error messages in Scala parser-combinator based parsers?

I've coded a parser based on Scala parser combinators: class SxmlParser extends RegexParsers with ImplicitConversions with PackratParsers { [...] lazy val document: PackratParser[AstNodeDocument] = ((procinst | element | comment | cdata | whitespace | text)*) ^^ { AstNodeDocument(_) } [...] } obje...

Running a method after the constructor of any derived class

Let's say I have a Java class abstract class Base { abstract void init(); ... } and I know every derived class will have to call init() after it's constructed. I could, of course, simply call it in the derived classes' constructors: class Derived1 extends Base { Derived1() { ... init(); } } class Deri...

Testing SocketChannel NIO

Hello, I just wrote some NIO-code and wonder how to stress-test my implementation regarding SocketChannel.write(ByteBuffer) not able to write the whole byte-buffer SocketChannel.read(ByteBuffer) reading the data in chunks into ByteBuffer are there some simple linux-utilities like telnet to open a ServerSocket with some buffering-op...

How do I parse an xml document as a stream using Scala?

How do I parse an xml document as a stream using Scala? I've used the Stax API in java to accomplish this, but I'd like to know if there is a "scala" way to do this. ...

OpenSSL compatible API for Scala?

Hello, I'm working on a project with a friend. He's implementing his software in Ruby and I'm doing my stuff in Scala (with Lift). We're using some asynchronous encryption and he is using the ruby OpenSSL bindings for that: key = OpenSSL::PKey::RSA.generate(4096) self.public_key = key.public_key self.private_key = key What I'm loo...

How can I get Syslogging to work on the JVM?

I want to do syslogging from Java. There is a log4j appender, but it doesn't seem to work (for me anyway ... though Google results show many others with this issue still unresolved). I'm trying to debug the appender, so I've written the following script based upon RFC3164 It runs, but no logging appears in the syslog. // scala import ...

Case class copy() method abstraction.

I would like to know if it is possible to abstract the copy method of case classes. Basically I have something like sealed trait Op and then something like case class Push(value: Int) extends Op and case class Pop() extends Op. The first problem: A case class without arguments/members does not define a copy method. You can try this in t...

Implement timeout in actors

Hi, I am new to scala and actors. I need to implement such hypothetical situation: Server wait for messages, if it does not get any in say 10s period of time, it sends message to the Client. Otherwise it receives messages incoming. If it is inside processing some message and another message comes, it needs to be queued (I suppose that ...

Scala model-view-presenter, traits

I am a fan of Martin Fowler's (deprecated) model-view-presenter pattern. I am writing a Scala view class containing several button classes. I would like to include methods to set the action properties of the buttons, to be called by the presenter. A typical code fragment looks like this: private val aButton = new JButton def setAButtonA...

Dynamic bind in Lift framework

I am newbie to Lift and I have a question on using bind, Ajax in Lift. I want to create three dropdown menus using Ajax in a dynamic fashion. I use "Address" as an example to describe what I am trying to achieve. At fist, I only have to display "Country" menu with default set to "None". The user at this point can choose to submit if she...

idiomatic property changed notification in scala?

I'm trying to find a cleaner alternative (that is idiomatic to Scala) to the kind of thing you see with data-binding in WPF/silverlight data-binding - that is, implementing INotifyPropertyChanged. First, some background: In .Net WPF or silverlight applications, you have the concept of two-way data-binding (that is, binding the value of ...

Working with images in Scala

I am generating large PNG files from a Scala program. Currently, I am doing it the same way I would do it in java. I am creating a new BufferedImage and setting each pixel to the correct color. This works fine, but I am wondering if there are any good libraries for working with images in Scala? I am looking for something like Ruby's ...

rewrite not a member of LiftRules

Hi guys, I was following http://www.assembla.com/wiki/show/liftweb/URL_Rewriting tutorial for url rewritting in liftweb.. but I get this error: error: value rewrite is not a member of object net.liftweb.http.LiftRules .. it is really odd.. and the documentation says that it exists. I'm using idea IDE, and I've done everything from sc...

How is `toString` in `scala.Enumeration$Value` implemented?

I have an enum Fruit defined as: object Fruit extends Enumeration { val Apple, Banana, Cherry = Value } Now printing values of this enum, on Scala 2.7.x gives: scala> Fruit foreach println line1$object$$iw$$iw$Fruit(0) line1$object$$iw$$iw$Fruit(1) line1$object$$iw$$iw$Fruit(2) However the same operation on Scala 2.8 gives: scal...

Packrat parsing HTTP

Hello could somebody give me a start on how to parse the HTTP-protocol with scala 2.8 packrat-parsing? I need to parse attached examplary HTTP Response into ResponseStatusCode:Int Headers:List[(String,String)] Body: String, Array[Byte], CharBuffer or whatever Short examplary usage of a Packrat-Parser very much appreciated. Thanks! ...

How to deploy a Scala project from Eclipse?

I have a Scala project in Eclipse that I need to package up so I can deploy it to a server. It's based on Jetty but it runs as a standalone application. It contains Scala classes, Java classes and a number of 3rd party jars. I assumed there would be some kind of deployment option in the Scala Eclipse plugin but I've drawn a blank. What...

Operator precedence in scala

I like scala's propose of operator precedence but in some rare case unmodified rules may be inconvenient because you have restrictions in naming your methods. Is there in scala ways to define another rules for a class/file/etc? If not would it be resolved in future? ...

How to convert a Seq[A] to a Map[Int, A] using a value of A as the key in the map?

I have a Seq containing objects of a class that looks like this: class A (val key: Int, ...) Now I want to convert this Seq to a Map, using the key value of each object as the key, and the object itself as the value. So: val seq: Seq[A] = ... val map: Map[Int, A] = ... // How to convert seq to map? How can I does this efficiently a...