scala

How to unimport String "+" operator in Scala?

I'm writing a DSL where the "+" operator is strictly numeric, like some other popular languages. It's close, but the String "+" operator is messing up my implicit conversions. What's the syntax for unimporting an operator of the String class? Just to be clearer, instead of this: scala> var x = "2" + 3; x: java.lang.String = 23 I'd l...

Stuck at "Hello World" with IntelliJ IDEA 9.0.1 for Scala

I've been using Eclipse since 2.x and IDEs in general for over 20 years (since Turbo Pascal and Turbo C in the late '80s!). (that preamble is supposed to imply, "I'm not an idiot" ... but doesn't sound so smart as I read it... LOL :-] ) Now I'm trying to use the Scala debugger in IntelliJ 9.0.1. I've resigned myself to an old standby, ...

How to create sorted map in scala?

How to create sorted map in scala (mutable/immutable)? ...

Parsing of binary data with scala

I need to parse some simple binary Files. (The files contains n entries which consists of several signed/unsigned Integers of different sizes etc.) In the moment i do the parsing "by hand". Does somebody know a library which helps to do this type of parsing? Edit: "By hand" means that i get the Data Byte by Byte sort it in to the corre...

Implementing Seq[T] for CPS-Classes

Having the following class which is in a CPS-context (@cps[Unit]) how would I implement the Seq-trait? Do I have to leave the standard traits like Seq aside and just implement map, flatmap and foreach in the cps-context? class DataFlowVariable[T] { def apply(): T @cps[Unit] = ... } class DataFlowStream[T] extends Seq[T] { override...

How to use Scala in IntelliJ IDEA (or: why is it so difficult to get a working IDE for Scala)?

I recently gave up trying to use Scala in Eclipse (basic stuff like completion doesn't work). So now I'm trying IntelliJ. I'm not getting very far. I've been able to edit programs (within syntax highlighting and completion... yay!). But I'm unable to run even the simplest "Hello World". This was the original error: Scala signature Pr...

How are Scala closures transformed to Java objects?

I'm currently looking at closure implementations in different languages. When it comes to Scala, however, I'm unable to find any documentation on how a closure is mapped to Java objects. It is well documented that Scala functions are mapped to FunctionN objects. I assume that the reference to the free variable of the closure must be st...

How Do I Convert Pipe Delimited to Comma Delimited with Escaping

Hi, I am fairly new to scala and I have the need to convert a string that is pipe delimited to one that is comma delimited, with the values wrapped in quotes and any quotes escaped by "\" in c# i would probably do this like this string st = "\"" + oldStr.Replace("\"", "\\\\\"").Replace("|", "\",\"") + "\"" I haven't validated that a...

Parser combinators info

I am using parsing combinators in scala If I have recursive parser: val uninterestingthings = ".".r val parser = "(?ui)(regexvalue)".r | (uninterestingthings~>parser) How can I check how many characters of input my parser consumed? ...

Have you actually convinced anybody to Scala?

I had limited success myself. I was able to hype a few persons about Scala. But in fact none of them made a meaningful effort to try to switch (usually from Java). I would like to read both success and failure stories here. Both long tries and short ones. My goal is to find ways of presenting Scala to another person, friend, co-worker ...

What are the exact versions of stuff you have to install in order to be able to step-debug a Scala program?

How do YOU debug a Scala program? I mean YOU as in the person posting the Answer :) Please answer only from personal experience, not from stuff you've heard or read on the Internet. You should not believe everything you read on the Internet, especially tales of complex open-source software configurations that actually work :-) The are...

Simple Scala syntax - trying to define "==" operator - what am I missing?

While experimenting with some stuff on the REPL, I got to a point where I needed something like this: scala> class A(x:Int) { println(x); def ==(a:A) : Boolean = { this.x == a.x; } } Just a simple class with an "==" operator. Why doesn't it work??? Here's the result: :10: error: type mismatch; found : A required: ?{val x: ?} ...

How do I get the scalaz IDEA live templates working for the symbolic methods?

Many of the methods in scalaz have symbolic unicode equivalents, such as forever and ∞ (of course, I have this the wrong way round, the symbolic methods really have ASCII equivalents). The project contains a live templates XML file for IDEA so these can be auto-completed, I believe by using the forever+TAB shortcut (in the above instanc...

How to make ensime work in windows?

I'm new to emacs and I want to use ensime in Windows. I had a try but it doesn't work. It seems that it doesn't work because there is a *nix format file named "\ensime\bin\server.sh" . Very appreciate if someone give me some tips. EDIT: I follow VonC's suggestion but it doesn't work perfect. I'm sure I have missed something. I have in...

Why scala 2.8 REPL does not auto-complete some method (i.e. forall, exists)?

I started the scala REPL an write the following code: scala> val a = Array(1,2,3,4) a: Array[Int] = Array(1, 2, 3, 4) scala> a.`<TAB>` asInstanceOf getClass isInstanceOf toString scala> a.exists(_ == 1) res1: Boolean = true Why I don't have "exists" listed when I press <TAB>? ...

Compilation issues using scalaz's MA methods on Set but not List

The following compiles just fine using scala Beta1 and scalaz snapshot 5.0: val p1: Int => Boolean = (i : Int) => i > 4 val s: List[Int] = List(1, 2, 3) val b1 = s ∃ p1 And yet this does not: val s: Set[Int] = Set(1, 2, 3) val b1 = s ∃ p1 I get the following error: Found: Int => Boolean Required: Boolean => Boolean The sig...

What compromises Scala made to run on JVM?

Scala is a wonderful language, but I wonder how could be improved if it had it's own runtime? I.e. what design choices were made because of JVM choice? ...

Scala puts precedence on implicit conversion over "natural" operations... Why? Is this a bug? Or am I doing something wrong?

This simple test, of course, works as expected: scala> var b = 2 b: Int = 2 scala> b += 1 scala> b res3: Int = 3 Now I bring this into scope: class A(var x: Int) { def +=(y:Int) { this.x += y } } implicit def int2A(i:Int) : A = new A(i) I'm defining a new class and a += operation on it, and a convenient implicit...

How do I enable continuations on Scala 2.8?

Scala 2.8.0.RC1 includes the continuations plugin on trunk for the first time, but the details of how to get access to the shift and reset operations have changed from previous releases, so it's difficult to follow the blog entries and SO answers out there that talk about continuations but were written for previous versions. See also ht...

Scala 2.8 TreeMap and custom Ordering

I'm switching from scala 2.7 and ordered to scala 2.8 and using ordering. It looks quite straight forward but I was wondering could I make it a little less verbose. For example: scala> case class A(i: Int) defined class A scala> object A extends Ordering[A] { def compare(o1: A, o2: A) = o1.i - o2.i} defined module A If I then try to c...