scala-2.10

Binary Serialization - replacing Marshal on scala 2.10

夙愿已清 提交于 2019-12-07 04:02:55
问题 how can I migrate this old code to scala 2.10 since scala.util.Marshal is deprecated ? object Serilaizer{ def objectToBytes[T](foo: T)(implicit expected: ClassManifest[T]): Array[Byte] = { Marshal.dump(foo) } def bytesToObject[T](fooBytes: Array[Byte])(implicit expected: ClassManifest[T]): Option[T] = { Some(Marshal.load[T](fooBytes)) } } I saw SBinary but it is not released yet. 回答1: this is what a came up with so far , implementing the original Marshal dump/load code (as in scala 2.9), not

ScalaMacros and Eclipse

拥有回忆 提交于 2019-12-07 00:56:03
问题 I am trying to compile a (Scala) macro in Eclipse 3.7.2 with the Scala IDE Plugin available for Scala 2.10.0-M3, but I am experiencing the following error: "macro implementation not found: XXXXX (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them) if you do need to define macro implementations along with the rest of your program, consider two-phase compilation with -Xmacro-fallback-classpath in the second phase pointing

Splicing together symbols with Scala macros

血红的双手。 提交于 2019-12-06 12:10:20
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 flavour? I know there are def macros, implicit macros, fundep materialization, macro annotations, type

Implicit parameter and ClassTag

亡梦爱人 提交于 2019-12-06 11:41:10
问题 Can someone explain what the Scala compiler is trying to tell me with the error message below? object Some { def apply[T: ClassTag](data: T)(implicit ordering: Ordering[T]): T = data } object Other { def apply[T: ClassTag](data: T)(implicit ordering: Ordering[T]): T = Some(data)(ordering.reverse) } Compiler says: not enough arguments for method apply: (implicit evidence$2: scala.reflect.ClassTag[T], implicit ordering: Ordering[T])T in object Some. Unspecified value parameter ordering. The

What is the easiest way to update an immutable AST?

你。 提交于 2019-12-06 03:29:01
问题 While working with macros, I have reached the point (I have been trying hard to avoid it) where I need to update those nodes in the AST which hold certain condition. For instance, let's say I would like to update each node: Literal(Constant(1)) with the value: Literal(Constant(2)) Those AST nodes could be anywhere in the expression tree, so I cannot use an ad-hoc pattern matcher. Obviously, the last thing I would like to do is to code a full pattern matcher which is able to cover all the

F-Bounded polymorphism with abstract types in Scala

℡╲_俬逩灬. 提交于 2019-12-06 03:15:40
问题 I have read several articles expressing that abstract types should be used to achieve f-bounded polymorphism in Scala. This is primarily to alleviate type inference issues, but also to remove the quadratic growth that type parameters seem to introduce when defining recursive types. These are defined as so: trait EventSourced[E] { self => type FBound <: EventSourced[E] { type FBound <: self.FBound } def apply(event: E): FBound } However, this appears to introduce two issues: 1) Each time a

Create a custom scala collection where map defaults to returning the custom collection?

一世执手 提交于 2019-12-06 01:59:43
问题 The trait TraversableLike[+A, +Repr] allows one to make a collection where some functions will return a Repr , while others continue to return the type parameter That on the function. Is there a way to define a CustomCollection[A] where functions like map , ++ , and others will default That as Repr if not inferred otherwise? Here is a code snippet that hopefully describes what I would like: case class CustomCollection[A](list: List[A]) extends TraversableLike[A, CustomCollection[A]] {

Can this free-term-variable error (produced at macro expansion) be avoided?

扶醉桌前 提交于 2019-12-05 23:14:07
问题 I am developing a DSL and I am getting a "free term" failure while expanding a macro. I would like to know if it can be avoided. I have simplified the problem to the following situation. Suppose we have this expression: val list = join { 0 1 2 3 } println(list) where join is a macro whose implementation is: def join(c: Ctx)(a: c.Expr[Int]): c.Expr[List[Int]] = { import c.mirror._ a.tree match { case Block(list, ret) => // c.reify(List(new c.Expr(list(0)).eval, // new c.Expr(list(1)).eval, //

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

不羁岁月 提交于 2019-12-05 14:22:51
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-mapreduce-client-core , hadoop-auth , hadoop-common Can someone help me understand why this difference in

Get filename of the current file in scala

守給你的承諾、 提交于 2019-12-05 12:49:57
Is there a way the file name of the current file (when the code is written) in scala? Like my class is in a file like com/mysite/app/myclass.scala and i want to call a method that will return "myclass.scala" (or the full path...) Thank you! This can be achieved with Scala macros , an experimental language feature available from version 2.10. Macros make it possible to interact with the building of the AST during the source code parsing phase, and to modify trees of AST before the actual compilation is performed. Since the information about the context of the compilation is available to the