scala-2.10

Scala reflection error: this is an inner module, use reflectModule on an InstanceMirror to obtain its ModuleMirror

时光毁灭记忆、已成空白 提交于 2019-12-19 08:59:09
问题 Following up on this question, I'm trying to figure out how to call a method on an object. The relevant definitions are: trait ThirdParty { def invoke = println("right") } trait WeatherIcon { def invoke = println("wrong") } class MyClass { object objA extends ThirdParty object objB extends WeatherIcon } I got a Symbol for objA like this: import reflect.runtime.universe._ val stuff = typeOf[MyClass].members.filter(_.isValue).filter(_.typeSignature <:< typeOf[ThirdParty]) That returns an

Scala Play 2.2 application crashes after deploying in Heroku: target/start No such file or directory

偶尔善良 提交于 2019-12-19 05:46:45
问题 I've been fighting with this for hours and I can't figure out why after deploying my Scala Play 2.2 application in Heroku I get this stacktrace: 2013-09-30T01:05:09.413177+00:00 heroku[web.1]: Starting process with command `target/start -Dhttp.port=18174 $PLAY_OPTS` 2013-09-30T01:05:10.931893+00:00 app[web.1]: bash: target/start: No such file or directory 2013-09-30T01:05:12.382399+00:00 heroku[web.1]: Process exited with status 127 2013-09-30T01:05:12.414050+00:00 heroku[web.1]: State

reducing an Array of Float using scala.math.max

二次信任 提交于 2019-12-19 03:31:09
问题 I am confused by the following behavior - why does reducing an Array of Int work using math.max, but an Array of Float requires a wrapped function? I have memories that this was not an issue in 2.9, but I'm not completely certain about that. $ scala -version Scala code runner version 2.10.2 -- Copyright 2002-2013, LAMP/EPFL $ scala scala> import scala.math._ scala> Array(1, 2, 4).reduce(max) res47: Int = 4 scala> Array(1f, 3f, 4f).reduce(max) <console>:12: error: type mismatch; found : (Int,

Scala error: class file is broken, bad constant pool index

你。 提交于 2019-12-19 02:32:15
问题 I'm trying to call the Selenium Java libraries from Scala. I'm using Scala IDE (Eclipse), and Scala 2.10.2. What is causing this compiler error? error while loading Function, class file '/Dev/selenium-2.35.0/libs/guava- 14.0.jar(com/google/common/base/Function.class)' is broken (class java.lang.RuntimeException/bad constant pool index: 0 at pos: 479) Sometimes I fix broken class file errors by including more jars -- jars that javac would not need to see, but apparently scalac does. But is

How do I print an expanded macro in Scala?

耗尽温柔 提交于 2019-12-18 18:51:11
问题 I am writing a macro in Scala, but when I call it I get an error message saying "Double does not take parameters". Clearly there is something wrong with how the macro builds the AST. So how can I see the expanded macro? Is there a way to call the macro implementation at runtime? 回答1: Provide -Ymacro-debug-lite or -Ymacro-debug-verbose option to the compiler. Off the top of my head, detalization of printed ASTs is governed by -Yshow-trees-compact , -Yshow-trees-stringified , -Xprint-types ,

How to write a Play JSON writes converter for a case class with a single nullable member

二次信任 提交于 2019-12-18 11:56:51
问题 In Play 2.3, I have a case class with a single optional double member: case class SomeClass(foo: Option[Double]) I need a JSON write converter that handles the member as nullable: implicit val someClassWrite: Writes[SomeClass] = ??? The Play docs provide an example: case class DisplayName(name:String) implicit val displayNameWrite: Writes[DisplayName] = Writes { (displayName: DisplayName) => JsString(displayName.name) } But sadly I can't figure out how to do this for 1) a single nullable and

How do the new Scala TypeTags improve the (deprecated) Manifests? [duplicate]

我是研究僧i 提交于 2019-12-18 10:41:38
问题 This question already has an answer here : Closed 6 years ago . Possible Duplicate: Scala 2.10: What is a TypeTag and how do I use it? I have been reading about the new TypeTags which come along with the new reflection api. It seems that Manifests are supposed to be replaced with that new concept. Can anyone post some code examples to show the benefits? Some references: TypeTags API SIP: Self-cleaning macros Metaprogramming in Scala 回答1: Manifests are a lie. It has no knowledge of variance

Option.fold in scala 2.10

混江龙づ霸主 提交于 2019-12-18 06:57:06
问题 In the following session with scala 2.10.0-M7: scala> trait A defined trait A scala> class B extends A defined class B scala> class C extends A defined class C scala> Some(0).fold(new B){_=>new C} <console>:11: error: type mismatch; found : C required: B Some(0).fold(new B){_=>new C} I would expect the compiler find the common supertype (namely A) rather than complaining. Is it the general type inference limitation, or the consequence of the way Option.fold is defined? Thank you. 回答1: The

Scala macro to print code?

孤者浪人 提交于 2019-12-18 05:01:49
问题 I want to do something like this: def assuming[A](condition: => Boolean)(f: => A): A = { require(condition, /* print source-code of condition */) f } Sample usage: def fib(n: Int) = n match { // yes, yes, I know this is not efficient case 0 => 0 case 1 => 1 case i => assuming(i > 0) { fib(i-1) + fib(i-2) } } Now, for example, if you call fib(-20) , I want it to throw an exception with a message like Assertion failed: -20 > 0 or Assertation failed: i > 0 回答1: Dude, isn't an assert macro one of

Scala macro to print code?

不想你离开。 提交于 2019-12-18 05:01:06
问题 I want to do something like this: def assuming[A](condition: => Boolean)(f: => A): A = { require(condition, /* print source-code of condition */) f } Sample usage: def fib(n: Int) = n match { // yes, yes, I know this is not efficient case 0 => 0 case 1 => 1 case i => assuming(i > 0) { fib(i-1) + fib(i-2) } } Now, for example, if you call fib(-20) , I want it to throw an exception with a message like Assertion failed: -20 > 0 or Assertation failed: i > 0 回答1: Dude, isn't an assert macro one of