scala-2.10

How can I reuse definition (AST) subtrees in a macro?

早过忘川 提交于 2019-12-09 05:28:03
问题 I am working in a Scala embedded DSL and macros are becoming a main tool for achieving my purposes. I am getting an error while trying to reuse a subtree from the incoming macro expression into the resulting one. The situation is quite complex, but (I hope) I have simplified it for its understanding. Suppose we have this code: val y = transform { val x = 3 x } println(y) // prints 3 where 'transform' is the involved macro. Although it could seem it does absolutely nothing, it is really

Is using Try[Unit] the proper way?

给你一囗甜甜゛ 提交于 2019-12-09 02:36:57
问题 I recently came across the concept of Try / Success / Failure , and I am wondering how to use it for a method that has the return type Unit . Is using Try[Unit] the correct way? Maybe I am too influenced from my Java background, but is it a good idea to force the caller to deal with the problem? 回答1: Try[Unit] is normal. For example, if you persist the entity, you can use: try { em.persist(entity) } catch{ case ex:PersistenceException => handle(ex) } or just Try(em.persist(entity)) match {

Typesafe stack and Scala 2.10 [closed]

假装没事ソ 提交于 2019-12-08 20:53:32
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . On scala's 2.10 download page ( http://www.scala-lang.org/downloads) is written: The Scala distribution is also available in a simple, pre-integrated

Strange behavior with reflection in Scala

白昼怎懂夜的黑 提交于 2019-12-08 19:38:07
问题 I was trying to follow an example from another question, and I came upon something I cannot explain: scala> import scala.reflect.runtime.{currentMirror => m} import scala.reflect.runtime.{currentMirror=>m} scala> m.mkToolBox() <console>:12: error: value mkToolBox is not a member of reflect.runtime.universe.Mirror m.mkToolBox() ^ scala> import scala.tools.reflect.ToolBox import scala.tools.reflect.ToolBox scala> m.mkToolBox() res3: scala.tools.reflect.ToolBox[reflect.runtime.universe.type] =

type arguments [W] do not conform to trait type parameter bounds

醉酒当歌 提交于 2019-12-08 15:15:10
问题 trait SomeClass { ... } trait AnotherClass[+V <: SomeClass] { ... } trait SomeAnotherClass[+V <: SomeClass] { protected def someFunc[W >: V](anotherClass: AnotherClass[W]) = { ... } } I'm getting this error: type arguments [W] do not conform to trait AnotherClass's type parameter bounds [+V <: SomeClass] [error] protected def someFunc[W >: V](anotherClass: AnotherClass[W]) = ... [error] ^ [error] one error found I don't get error when I do [W >: V <: SomeClass] instead of just [W >: V] , but

Splicing together symbols with Scala macros

喜你入骨 提交于 2019-12-08 00:19:41
问题 I am trying to call a specialized collections library like FastUtil or Trove from generic Scala code. I would like to implement something like def openHashMap[@specialized K, @specialized V]: ${K}2${V}OpenHashMap = new ${K}2${V}OpenHashMap() Where the ${X} is clearly not valid Scala, but just my meta notation for text substitution, so that openHashMap[Long, Double] would return a Long2DoubleOpenHashMap the type would be known at compile time. Is this possible with Scala macros. If so, which

Json Coast to Coast Play framework : Serializing Joda DateTime

半世苍凉 提交于 2019-12-07 19:30:18
问题 Hi all I am new to play framework, if someone knows of a better approach then mentioned below please let me know. So I have a model and Reads/Writes/Format for it case class Schedule (startDate: DateTime, endDate: DateTime) object ScheduleSerializers { val userDateFormatter = "dd/MM/yyyy HH:mm:ss" val nonImplicitUserFormatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss") implicit val jodaDateTimeReads = Reads.jodaDateReads(userDateFormatter) implicit val jodaDateTimeWrites = Writes

SBT not resolving transitive dependencies in the <Profile> section of POM

為{幸葍}努か 提交于 2019-12-07 11:39:42
问题 If the POM.xml of a dependency has transitive dependencies inside "Profile" section of pom.xml then those dependencies are not resolved by SBT whereas they are resolved by Maven. Eg: when the following dependency is included in a project..... <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> <version>0.98.0-hadoop2</version> </dependency> ...then the following dependencies are not resolved by SBT but are resolved by maven : hadoop-annotations , hadoop

Getting type information inside scala repl via IMain

送分小仙女□ 提交于 2019-12-07 04:38:03
问题 Intent I am trying to add support for :kind command to scala repl. Thanks to Eugene Burmako, I was able to get a working prototype. Though it only works with fully qualified names and fails to resolve imported names. I am now trying to use IMain.exprTyper to do the job, as it is aware of types, imported into the repl. But there is a problem. Everything I've tried returns a ClassInfoType like the following (displayed with showRaw): ClassInfoType(List(TypeRef(TypeRef(TypeRef(TypeRef(NoPrefix(),

Suppressing @unchecked warning for a higher-kinded existential type

£可爱£侵袭症+ 提交于 2019-12-07 04:27:53
问题 In Scala 2.10, given class Foo[F[_]] , I can't write scala> x.isInstanceOf[Foo[_]] <console>:10: error: _$1 takes no type parameters, expected: one x.isInstanceOf[Foo[_]] ^ or scala> x.isInstanceOf[Foo[_[_]]] <console>:11: error: _$1 does not take type parameters x.isInstanceOf[Foo[_[_]]] ^ I can write x.isInstanceOf[Foo[F] forSome { type F[_]] } , which gives an unchecked warning. I've tried placing @unchecked annotation in different places, but none of them work: scala> x.isInstanceOf[Foo[H