scala-2.8

Proxies / delegates in Scala

扶醉桌前 提交于 2019-11-28 04:34:31
I've seen several Scala questions recently (e.g. here , here , and here ) that called for the use of proxies, and it's come up more than once in my own work. The Scala library has a number of proxy traits (14, if I counted correctly). Proxy classes/traits usually contain lots of boilerplate: class FooProxy(val self: Foo) extends Foo { // added behavior def mymethod = ... // forwarding methods def method1 = self.method1 def method2(arg: String) = self.method2(arg) ... } trait Foo { def method1: Unit def method2(arg: String): Unit } My first thought was to define a Proxy[T] trait that could be

How to correctly type-annotate this HList?

两盒软妹~` 提交于 2019-11-28 01:21:41
问题 sealed abstract trait HList case class :+:[H, T <: HList](head: H, tail: T) extends HList { def :+:[T](v: T) = new :+:(v, this) } case object HNil extends HList { def :+:[T](v: T) = new :+:(v, this) } object HListExpt { def main(args: Array[String]) { val me: String :+: Int :+: Symbol :+: HNil.type = "Rahul" :+: 20 :+: 'Male :+: HNil println(me.head, me.tail.head) } } On trying to compile the above code, I get the following compiler error: error: type mismatch; found : :+:[java.lang.String,:+

How do I find out Apache Buildr/Maven 2 repo names

半腔热情 提交于 2019-11-27 18:38:27
I'm just starting to use Apache Buildr and I'm constantly running into the problem of not knowing what repo urls and versions are available for me to use. For example I want to use Scala 2.8 in a build file, the id i previously used was: 2.8.0-SNAPSHOT But now this is not found. I also want to use the latest version of Apache POI. If I look on the maven2 repo: http://mirrors.ibiblio.org/maven2/ I can see that it only has up to version 3.2. Is there any standard way of finding repos and searching them for what they have available? Is there any standard way of finding repos and searching them

Package objects

馋奶兔 提交于 2019-11-27 17:09:08
What are package objects, not so much the concept but their usage? I've tried to get an example working and the only form I got to work was as follows: package object investigations { val PackageObjectVal = "A package object val" } package investigations { object PackageObjectTest { def main(args: Array[String]) { println("Referencing a package object val: " + PackageObjectVal) } } } Observations I've made so far are: package object _root_ { ... } is disallowed (which is reasonable), package object x.y { ... } is also disallowed. It seems that a package object must be declared in the immediate

pass variable number of arguments in scala (2.8) case class to parent constructor

末鹿安然 提交于 2019-11-27 16:27:17
问题 I was experimenting with variable constructor arguments for case classes in Scala, but am unable to pass them to the constructor of a case classes' parent: abstract case class Node(val blocks: (Node => Option[Node])*) case class Root(val elementBlocks: (Node => Option[Node])*) extends Node(elementBlocks) the above doesn't compile... is it actually possible to do this? 回答1: This works with 2.7: abstract case class A(val a: String*) case class B(val b: String*) extends A(b:_*) Should work with

What's the motive behind Chained Package clauses in Scala?

自闭症网瘾萝莉.ら 提交于 2019-11-27 16:19:44
问题 Chained package clause were introduced in Scala 2.8, as described by Martin Odersky on the Scala site. I don't quite get the intuition behind this. Following was the example in the Scala book for the nested packages: package bobsrockets { package navigation { // In package bobsrockets.navigation class Navigator package tests { // In package bobsrockets.navigation.tests class NavigatorSuite } } } This use case of nested packages made sense because we could use multiple nested packages in the

When is a return type required for methods in Scala?

耗尽温柔 提交于 2019-11-27 15:06:49
问题 The Scala compiler can often infer return types for methods, but there are some circumstances where it's required to specify the return type. Recursive methods, for example, require a return type to be specified. I notice that sometimes I get the error message "overloaded method (methodname) requires return type", but it's not a general rule that return types must always be specified for overloaded methods (I have examples where I don't get this error). When exactly is it required to specify

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

守給你的承諾、 提交于 2019-11-27 12:32:03
How can I convert immutable.Map to mutable.Map in Scala so I can update the values in Map? 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. val myImmutableMap = collection.immutable.Map(1->"one",2->"two") val myMutableMap = collection.mutable.Map() ++

Which IDE for Scala 2.8?

余生颓废 提交于 2019-11-27 11:46:52
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? 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 clear, I've been using IDEA for a few years for Java, so keep that in mind:) For the moment, Scala Plugin in

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

一曲冷凌霜 提交于 2019-11-27 11:40:17
@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 annotation.unchecked._ import annotation.unchecked._ scala> trait Foo[-T] extends Comparator[T