scala-2.8

Scala: is it possible to override default case class constructor?

你。 提交于 2019-11-27 03:10:00
问题 Just wondering if this is possible. What I would actually like to do is check and possibly modify one of the arguments before it is stored as a val. Alternatively, I could use an overload and make the default constructor private. In which case I would also like to make private the default factory constructor in the companion object, how would I do that? Many thanks. Adam edit: well i figured out that making the default constructor private also makes the default factory constructor private, so

Implementing yield (yield return) using Scala continuations

对着背影说爱祢 提交于 2019-11-27 03:04:05
How might one implement C# yield return using Scala continuations? I'd like to be able to write Scala Iterator s in the same style. A stab is in the comments on this Scala news post , but it doesn't work (tried using the Scala 2.8.0 beta). Answers in a related question suggest this is possible, but although I've been playing with delimited continuations for a while, I can't seem to exactly wrap my head around how to do this. Before we introduce continuations we need to build some infrastructure. Below is a trampoline that operates on Iteration objects. An iteration is a computation that can

Scala 2.8 collections design tutorial

為{幸葍}努か 提交于 2019-11-27 02:28:32
Following on from my breathless confusion , what are some good resources which explain how the new Scala 2.8 collections library has been structured. I'm interested to find some information on how the following fit together: The collection classes/traits themselves (e.g. List , Iterable ) Why the Like classes exist (e.g. TraversableLike ) What the companion methods are for (e.g. List.companion ) How I know what implicit objects are in scope at a given point Daniel C. Sobral Foreword There's a 2.8 collection walk-through by Martin Odersky which should probably be your first reference. It has

Reflection on a Scala case class

半城伤御伤魂 提交于 2019-11-27 02:22:29
问题 I'm trying to write a trait (in Scala 2.8) that can be mixed in to a case class, allowing its fields to be inspected at runtime, for a particular debugging purpose. I want to get them back in the order that they were declared in the source file, and I'd like to omit any other fields inside the case class. For example: trait CaseClassReflector extends Product { def getFields: List[(String, Any)] = { var fieldValueToName: Map[Any, String] = Map() for (field <- getClass.getDeclaredFields) {

What are nested/unnested packages in Scala 2.8?

瘦欲@ 提交于 2019-11-27 02:11:28
问题 In Scala 2.7, I could write: package com.acme.bar class Bar . package com.acme.foo class Foo { new bar.Bar } This doesn't compile in Scala 2.8 -- however this does: package com.acme package bar class Bar . package com.acme package foo class Foo { new bar.Bar } What was the motivation for this? What is the precise meaning, with regards to scope and visibility? When should I use one form over the other? 回答1: There were several long discussions on the mailing lists about this. See this thread

Scala Map implementation keeping entries in insertion order?

拟墨画扇 提交于 2019-11-26 22:43:02
In Java, I use LinkedHashMap for this purpose. The documentation of Java's LinkedHashMap is very clear that it has "predictable iteration order" and I need the same in Scala. Scala has ListMap and LinkedHashMap , but the documentation on what they do exactly is poor. Question: Is Scala's LinkedHashMap or ListMap the implementation to use for this purpose? If not, what other options are available besides using the Java's LinkedHashMap directly? From the LinkedHashMap Scaladoc page: "This class implements mutable maps using a hashtable. The iterator and all traversal methods of this class visit

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

浪子不回头ぞ 提交于 2019-11-26 16:35:23
问题 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" // <-- uncomment } def bar() { "A" ==> "B" "B" ==> "C" "C" ==> "D" } object Implicits { implicit def string2Wrapper(s: String) = new Wrapper(s) class Wrapper(s: String) { def ==>(s2:

How can I convert immutable.Map to mutable.Map in Scala?

本小妞迷上赌 提交于 2019-11-26 16:02:44
问题 How can I convert immutable.Map to mutable.Map in Scala so I can update the values in Map? 回答1: The cleanest way would be to use the mutable.Map varargs factory. Unlike the ++ approach, this uses the CanBuildFrom mechanism, and so has the potential to be more efficient if library code was written to take advantage of this: val m = collection.immutable.Map(1->"one",2->"Two") val n = collection.mutable.Map(m.toSeq: _*) This works because a Map can also be viewed as a sequence of Pairs. 回答2: val

Which IDE for Scala 2.8?

故事扮演 提交于 2019-11-26 15:45:17
问题 This is the same question for older version of Scala, but they say that Eclipse plugin has been improved vastly. Is it the best IDE now? How do different Scala IDE compare today? 回答1: I've been pretty successful with IDEA 9. I've briefly tried both Netbeans and Eclipse and wasn't able to get what I wanted. Eclipse's code-complete didn't behave as well as I'd have liked, and I couldn't find a way to make Netbeans handle Scala scripts; It'd just complain that the file wasn't a class. To be

When is @uncheckedVariance needed in Scala, and why is it used in GenericTraversableTemplate?

被刻印的时光 ゝ 提交于 2019-11-26 15:40:36
问题 @uncheckedVariance can be used to bridge the gap between Scala's declaration site variance annotations and Java's invariant generics. scala> import java.util.Comparator import java.util.Comparator scala> trait Foo[T] extends Comparator[T] defined trait Foo scala> trait Foo[-T] extends Comparator[T] <console>:5: error: contravariant type T occurs in invariant position in type [-T]java.lang.Object with java.util.Comparator[T] of trait Foo trait Foo[-T] extends Comparator[T] ^ scala> import