scala

Scala's tuple unwrapping nuance

I've noticed the following behavior in scala when trying to unwrap tuples into vals: scala> val (A, B, C) = (1, 2, 3) <console>:5: error: not found: value A val (A, B, C) = (1, 2, 3) ^ <console>:5: error: not found: value B val (A, B, C) = (1, 2, 3) ^ <console>:5: error: not found: value C ...

mvn scala:script -DscriptFile=scripts/PrintHello.scala --> Does scripts folder to be part of the project?

Maven Scala: I created a scala project using archetype: mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create \ -DarchetypeGroupId=org.scala-tools.archetypes \ -DarchetypeArtifactId=scala-archetype-simple \ -DarchetypeVersion=1.1 \ -DremoteRepositories=http://scala-tools.org/repo-releases \ -DgroupId...

Scala: when are singleton objects constructed?

In object O { // construction code and member initialization } construct, when is this code going to be run? ...

Is there an implementation of rapid concurrent syntactical sugar in scala? eg. map-reduce

Passing messages around with actors is great. But I would like to have even easier code. Examples (Pseudo-code) val splicedList:List[List[Int]]=biglist.partition(100) val sum:Int=ActorPool.numberOfActors(5).getAllResults(splicedList,foldLeft(_+_)) where spliceIntoParts turns one big list into 100 small lists the numberofactors part, ...

trait implementation

If I have some traits like: trait A {...} trait B extends A{...} trait C1 extends B{...} trait C2 extends A{...} I can write class in two ways (C1 and C2 add same functionality) class Concrete1 extends B with C1 class Concrete2 extends B with C2 What variant is better(efficient)? ...

Restrictions in trait mixing

I want to have classes that can mix only specified traits: class Peter extends Human with Lawful with Evil class Mag extends Elf with Chaotic with Neutral Is in scala a way to do this? UPD: trait Law trait Lawful extends Law trait LNeutral extends Law trait Chaotic extends Law trait Moral trait Good extends Moral trait Neutral exte...

Using scala-2.8.0.RC1 with Maven and Intellij 9.0.1

I am trying to build a project using the newest release candidate of Scala (scala-2.8.0.RC1) and Maven in Intellij CE (9.0.1) -- I cannot upgrade to 9.0.2 because it breaks the La Clojure plugin. If I change my pom.xml to use the scala-2.8.0.RC1, Intellij tells me that Array is not defined (highlights in red). If I change to scala-2.8.0...

Why does this explicit call of a Scala method allow it to be implicitly resolved?

Why does this code fail to compile, but compiles successfully when I uncomment the indicated line? (I'm using Scala 2.8 nightly). It seems that explicitly calling string2Wrapper allows it to be used implicitly from that point on. class A { import Implicits.string2Wrapper def foo() { //string2Wrapper("A") ==> "B" // <-- uncommen...

Scala: working around the "illegal cyclic reference"

Hi all, I'm trying to implement a HashMap-based tree that'd support O(1) subtree lookup for a given root key. To that goal, I'm trying to do the following: scala> type Q = HashMap[Char, Q] <console>:6: error: illegal cyclic reference involving type Q type Q = HashMap[Char, Q] ^ So the question is, is...

Error with default argument in Source.getLines (Scala 2.8.0 RC1)

assuming I running Scala 2.8.0 RC1, the following scala code should print out the content of the file "c:/hello.txt" for ( line<-Source.fromPath( "c:/hello.txt" ).getLines ) println( line ) However, when I run it, I get the following error <console>:10: error: missing arguments for method getLines in class Source; ...

nested CPS "reset"

Hi, using the CPS compiler-plugin of Scala 2.8, there are the two magic controls reset and shift. Reset delimits the continuation and shift captures the continuation. There is an example of using CPS with NIO, using nested resets as a type of "forking"...? I don't exactly understand the purpose of nesting the resets, what's the effect? ...

Inheritance and type parameters of Traversable

I'm studying the source code of the Scala 2.8 collection classes. I have questions about the hierarchy of scala.collection.Traversable. Look at the following declarations: package scala.collection trait Traversable[+A] extends TraversableLike[A, Traversable[A]] with GenericTraversableTemplate[A, Traversable] tr...

Scala 2.8: _ behaviour changed?

Using XScalaWT, this compiled under Scala 2.7: class NodeView(parent: Composite) extends Composite(parent) { var nodeName: Label = null this.contains( label( nodeName = _ ) ) } With 2.8.0 RC1, I get this error: type mismatch; found : main.scala.NodeView required: org.eclipse.swt.widgets.Label The types ...

Abstract attributes in Python

What is the shortest / most elegant way to implement the following Scala code with an abstract attribute in Python? abstract class Controller { val path: String } A subclass of Controller is enforced to define "path" by the Scala compiler. A subclass would look like this: class MyController extends Controller { override va...

Newbie OutOfMemory problem

I am trying to create a producer/consumer type Scala app. The LoopControl just sends a message to the MessageReceiver continually. The MessageReceiver then delegates work to the MessageCreatorActor (whose work is to check a map for an object, and if not found create one and start it up). Each MessageActor created by this MessageCreatorA...

How do I break out of a loop in Scala?

For Problem 4 of Project Euler How do I break out a loop? var largest=0 for(i<-999 to 1 by -1) { for (j<-i to 1 by -1) { val product=i*j if (largest>product) // I want to break out here else if(product.toString.equals(product.toString.reverse)) largest=largest max product } } And does anyone know how to turn nested for l...

Scala 2.7 : reference is ambiguous (imported twice)

In Scala 2.7, I want to use a method as a parameter of another method of the same class. I have a class and objects which are companions: class mM(var elem:Matrix){ //apply a function on a dimension rows (1) or cols (2) def app(func:Iterable[Double]=>Double)(dim : Int) : Matrix = { ... } //utility function ...

Difference betwean RegexpParsers,StandardTokenParsers and JavaTokenParsers in scala

I am learning Parser Combinators in scala and seeing different ways of parsing.I mainly see three different kind of parsers ie.RegexpParsers,StandardTokenParsers and JavaTokenParsers.I am new to parsing and not getting the idea how we will choose the suitable Parser according to our requirement.Can any one please explain how these differ...

Scala return type for tuple-functions

Hello Guys, I want to make a scala function which returns a scala tuple. I can do a function like this: def foo = (1,"hello","world") and this will work fine, but now I want to tell the compiler what I expect to be returned from the function instead of using the built in type inference (after all, I have no idea what a (1,"hello","w...

Implicit parameter in Scalaz

I try to find out why the call ∅ in scalaz.ListW.<^> works def <^>[B: Zero](f: NonEmptyList[A] => B): B = value match { case Nil => ∅ case h :: t => f(Scalaz.nel(h, t)) } My minimal theory is: trait X[T]{ def y : T } object X{ implicit object IntX extends X[Int]{ def y = 42 } implicit object StringX extends X[Strin...