I've been learning Scala recently, and it seems like a very very promising general purpose programming language. It has all the good functional programming features, terse syntax, it runs on JVM and interoperates with Java.
Some think it's the Next Big Language. Others aren't so sure.
Why do you think it is/isn't going to be the next b...
I'm trying to mixin the MultiMap trait with a HashMap like so:
val children:MultiMap[Integer, TreeNode] =
new HashMap[Integer, Set[TreeNode]] with MultiMap[Integer, TreeNode]
The definition for the MultiMap trait is:
trait MultiMap[A, B] extends Map[A, Set[B]]
Meaning that a MultiMap of types A & B is a Map of types A & Set[B]...
Hello,
I've recently been working on a beginner's project in Scala, and have a beginner question about Scala's Lists.
Say I have a list of tuples ( List[Tuple2[String, String]], for example). Is there a convenience method to return the first occurence of a specified tuple from the List, or is it necessary to iterate through the list by...
I've recently become interested in learning Scala, my first thought was a simple compiler, but I don't have very good knowledge of Automata theory.
So my question is: what's a good project or tutorial to learn scala with?
...
Is there a functional language that has good support and tools for building web services? I've been looking at Scala (which compiles to the JVM and can use the Java libraries) and F# (which is .NET), but these are young and have some inefficiencies. Scala in particular doesn't support tail-call elimination except in self-recursive func...
I saw this on a question:
Scala in particular doesn't support tail-call elimination except in self-recursive functions, which limits the kinds of composition you can do (this is a fundamental limitation of the JVM).
Is this true? If so, what is it about the JVM that creates this fundamental limitation?
...
I want to add a property to my User model that returns the number of rows in the Project table that have a user Id of the user.
So something like this...
def numProjects = {
/* somehow get count from Project table
The straight sql would be:
SELECT COUNT(*) FROM projects WHERE userId =
*/
}
...
Using Scala's command line REPL:
def foo(x: Int): Unit = {}
def foo(x: String): Unit = {println(foo(2))}
gives
error: type mismatch;
found: Int(2)
required: String
It seems that you can't define overloaded recursive methods in the REPL. I thought this was a bug in the Scala REPL and filed it, but it was almost instantly closed with...
Could someone describe what are the differences between those two languages? Other that they target different VM of course ;)
...
I've been trying to encode a relational algebra in Scala (which to my knowlege has one of the most advanced type systems) and just don't seem to find a way to get where I want.
As I'm not that experienced with the academic field of programming language design I don't really know what feature to look for.
So what language features would...
Lets say I have the following code:
abstract class Animal
case class Dog(name:String) extends Animal
var foo:Animal = Dog("rover")
var bar:Dog = foo //ERROR!
How do I fix the last line of this code? Basically, I just want to do what, in a C-like language would be done:
var bar:Dog = (Dog) foo
...
In javascript, we can do:
["a string", 10, {x : 1}, function() {}].push("another value");
What is the Scala equivalent?
...
Has anyone out there worked on, or know of any real-world Scala applications? There has been a lot of talk lately, and I have even gone so far as to start learning it. I'd like to know if there are any real-world indicators out there as to whether my benefit from learning scala will be purely academic, or whether this skill will be wor...
In Scala, is it possible to get the string representation of a type at runtime? I am trying to do something along these lines:
def printTheNameOfThisType[T]() = {
println(T.toString)
}
...
It seems that there has been a recent rising interest in STM (software transactional memory) frameworks and language extensions. Clojure in particular has an excellent implementation which uses MVCC (multi-version concurrency control) rather than a rolling commit log. GHC Haskell also has an extremely elegant STM monad which also allow...
If you have something like:
val myStuff = Array(Person("joe",40), Person("mary", 35))
How do you create an XML value with that data as nodes? I know how to use { braces } in an XML expression to put a value, but this is a collection of values. Do I need to iterate explicitly or is there something better?
val myXml = <people>{ /* what...
I want to create a class that takes string array as a constructor argument and has command line option values as members vals. Something like below, but I don't understand how the Bistate works.
import scalax.data._
import scalax.io.CommandLineParser
class TestCLI(arguments: Array[String]) extends CommandLineParser {
private val op...
Hi,
I'm doing Cay Horstmann's combinator parser exercises, I wonder about the best way to distinguish between strings that represent numbers and strings that represent variables in a match statement:
def factor: Parser[ExprTree] = (wholeNumber | "(" ~ expr ~ ")" | ident) ^^ {
case a: wholeNumber => Number(a.toInt)
case a: Stri...
While playing around with regexps in Scala I wrote something like this:
scala> val y = "Foo"
y: java.lang.String = Foo
scala> y "Bar"
scala>
As you can see, the second statement is just silently accepted. Is this legal a legal statement, and if so, what does it do? Or is it a bug in the parser and there should be an error message?
...
Over the years, I think I have seen and tried every conceivable way of generating stub data structures (fake data) for complex object graphs. It always gets hairy in java.
* * * *
A---B----C----D----E
(Pardon cheap UML)
The key issue is that there are certain relationships between the values, so a certain instance of C m...