scala

Updating intelliJ IDEA

I'm using IntelliJ IDEA 9.0 community edition. The Scala plugin I use uses Scala 2.7.6. How do I update the plugin for Scala 2.8? Thanks. ...

Does extending a class in scala with constructor params add vals (fields) to the class?

Say I have: class A(val foo: String) class B(foo: String) extends A(foo) class C(val foo: String) extends A(foo) class D(override val foo: String) extends A(foo) class E(bar: String) extends A(bar) I'm interested in how much memory instances of each of these classes take up. Instances of class A will have a single member variable: f...

Are there any books covering Scala 2.8 available?

I've been learning Scala with the Odersky/Venners book using Scala 2.7. Now I'd want to jump to 2.8, but people are saying that there are a lot of changes and some of them are not backwards compatible. This sounds like a big headache unless there is a nice book out there covering the new version of the language. So does such book exist? ...

How to test arguments to a case class constructor?

I'd like to test the arguments to my case class constructor and throw an exception if they fail certain tests. The compiler complained when I tried to write my own apply method (Multiple 'apply' methods. I suppose I could make it a non-case class, and do the apply/unapply constructor field stuff myself, but I had hoped not to. Thanks ...

Can I name a tuple (define a structure?) in Scala 2.8?

It does not look very good for me to always repeat a line-long tuple definition every time I need it. Can I just name it and use as a type name? Would be nice to name its fields also instead of using ._1, ._2 etc. ...

Squeryl - "CustomTypesMode is not a member of package org.squeryl.customtypes"?

I've built Squeryl framework with SBT and am trying to use it with Scala 2.8 and NetBeans 6.9. I've defined an entity model as it is desctibed in Squeryl intro, but the IDE and compiler complain that "CustomTypesMode is not a member of package org.squeryl.customtypes". What might the reason be? ...

how to expose test for a pattern match

Hi, I'm rater new to scala, but basically have found my way around... Here, I'm asking for the recommended/best practice/idiomatic way of implementing this: internally, MyClass uses a state type, which is implemented by a sealed hierarchy of case classes but on the API, only some boolean predicate should be exposed, which gets impleme...

Disadvantages of Scala type system versus Haskell?

I have read that Scala's type system is weakened by Java interoperability and therefore cannot perform some of the same powers as Haskell's type system. Is this true? Is the weakness because of type erasure, or am I wrong in every way? Is this difference the reason that Scala has no typeclasses? ...

ScalaTest: check for contents of a sequence with ShouldMatcher

In my unit test, I want to express that a computed (result) sequence yielded a predefined sequence of result values. But without assuming anything about the actual implementation type of the sequence container. And I want to spell out my intent rather clear and self-explanatory. If I try to use the "ShouldMatchers" of ScalaTest and writ...

Scala + Akka: How to develop a Multi-Machine Highly Available Cluster

We're developing a server system in Scala + Akka for a game that will serve clients in Android, iPhone, and Second Life. There are parts of this server that need to be highly available, running on multiple machines. If one of those servers dies (of, say, hardware failure), the system needs to keep running. I think I want the clients t...

Cannot create apply function with static language?

I have read that with a statically typed language like Scala or Haskell there is no way to create or provide a Lisp apply function: (apply #'+ (list 1 2 3)) => 6 or maybe (apply #'list '(list :foo 1 2 "bar")) => (:FOO 1 2 "bar") (apply #'nth (list 1 '(1 2 3))) => 2 Is this a truth? ...

Better GUI classes organization?

I am currently trying to program in Scala but I guess this can generally applies to other programming as well? In Swing, we generally organize our code and logic in a single class (perhaps our Frame or Panel). What I have learnt in the pass has always been dealing with a class as well. I am wondering if there is any medium size (not too...

How to update a mutable hashmap element in Scala?

I wrote a function very similar to this: def writeMyEl (x: TypeA, y: TypeB, z : TypeC) { if (myMutableHashMap.contains((x, y))) myMutableHashMap(x, y) = z else myMutableHashMap += (x, y) -> z } In real code Types A and B are enumerations ans C is a case class. myMutableHashMap is defined as a val of type scala.collectio...

How to use java.String.format?

I am trying to use a .format method of a string. But if I place %1, %2 etc in the string, java.util.UnknownFormatConversionException is thrown pointing to a confusing Java source code piece: private void checkText(String s) { int idx; // If there are any '%' in the given string, we got a bad format // specifier. if ((idx = s.in...

Inheritance and (automatic?) type conversion

Hi. Please have a look at the followin code, where Extractor[A,B] is part of a generic framework and everything else should be regarded as "client code" (I boiled it a down quite a bit and renamed everything. So don't mind that Extractor doesn't seem to be too usefull). scala> abstract class Extractor[A,B] { ...

How o run a NetBeans-built Scala application jar from command line outside IDE?

A program of mine (written in Scala 2.8) works fine when launched by means of NetBeans IDE. But when I try to run it from outside, with "java- jar", it says "Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject...". Putting all the libraries, incl. Scala runtime inside the same dir as the jar to be run doesn't hel...

Split string into equal-length substrings in Scala

Im looking for an elegant way in Scala to split a given string into substrings of fixed size (the last string in the sequence might be shorter). So split("Thequickbrownfoxjumps", 4) should yield ["Theq","uick","brow","nfox","jump","s"] Of course I could simply use a loop but there has to be a more elegant (functional style) soluti...

Can you recommend a good shared hosting provider for a webapp made with Lift framework with Scala 2.8?

I've got acquainted with Scala recently and found it beautiful. I am willing to give up using PHP and use Scala instead for all projects of mine. Now I Use BlueHost for hosting my PHP-based sites. Can you recommend a good alternative that will support Scala? ...

Scala MouseEvent - How to know which button was pressed?

I'm writing a scala application using scala swing. I can listen for MouseClicked to get notified whenever the mouse is clicked, but how do i know which button was pressed. The documentation is pretty bad, so i have looked in the Java documentation for MouseEvent, which says that the key can be retrieved from the modifiers field, so i tri...

Can you recommend a charting library for Scala?

I need to plot some 2d (y=f(x)) and 3d (real z=f(x,y), not just 3d-looking) datasets, as well as graphs (directed and not) from my Scala (2.8) application. Currently I am going to output charts data to text files and use external charting applications (like SciDAVis). But maybe there are more convenient and automated solutions available ...