scala-2.10

Suppressing @unchecked warning for a higher-kinded existential type

拈花ヽ惹草 提交于 2019-12-05 11:38:56
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] @unchecked forSome {type H[_]}] <console>:11: warning: abstract type H in type Foo[H] @unchecked

Type equality in the Scala 2.10 Reflection API

浪子不回头ぞ 提交于 2019-12-05 09:17:33
I'm running into a weird issue with reflection in Scala 2.10.0 Milestone 4 that I can't wrap my head around. First for the stuff that works the way I'd expect: scala> import scala.reflect.runtime.universe._ import scala.reflect.runtime.universe._ scala> trait A[X]; trait B[Y] extends A[Y] defined trait A defined trait B scala> typeOf[B[String]].parents res0: List[reflect.runtime.universe.Type] = List(java.lang.Object, A[String]) scala> typeOf[B[String]].parents contains typeOf[A[String]] res1: Boolean = true Similarly (in the same session): scala> trait D; trait E extends A[D] defined trait D

Strange error with higher-kinded types in scala 2.10.0 (works with scala 2.9.2)

混江龙づ霸主 提交于 2019-12-05 08:10:39
This code compiles with Scala 2.9.2: trait HK { type Rep[A] def unzip1[A, B, C[_]](ps: Rep[C[(A, B)]]): (Rep[C[A]], Rep[C[B]]) def doUnzip1[A, B](ps: Rep[List[(A, B)]]) = unzip1(ps) } But with Scala 2.10.0 it doesn't compile with the following error (higherKinded language feature is enabled): [info] Compiling 1 Scala source to /home/klyuchnikov/code/hk/target/scala-2.10/classes... [error] /home/klyuchnikov/code/hk/src/main/scala/HK.scala:6: type mismatch; [error] found : HK.this.Rep[List[(A, B(in method doUnzip1))]] [error] required: HK.this.Rep[List[((A, B(in method doUnzip1)), B(in method

ScalaMacros and Eclipse

限于喜欢 提交于 2019-12-05 05:00:53
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 to the output of the first phase" I already know how to avoid it with a simple editor and a terminal

No multipartconfig for servlet error from Jetty using scalatra

天大地大妈咪最大 提交于 2019-12-05 02:29:11
I am trying to unit test an upload call but I get this error for the following code: @MultipartConfig(maxFileSize = 3145728) class WebServlet extends ScalatraServlet with FileUploadSupport { override def isSizeConstraintException(e: Exception) = e match { case se: ServletException if se.getMessage.contains("exceeds max filesize") || se.getMessage.startsWith("Request exceeds maxRequestSize") => true case _ => false } error { case e: SizeConstraintExceededException => RequestEntityTooLarge("too much!") } post("/uploadscript") { val privateParam = try {params("private") != null && params("private

Compare data in two RDD in spark

半城伤御伤魂 提交于 2019-12-05 01:57:54
问题 I am able to print data in two RDD with the below code. usersRDD.foreach(println) empRDD.foreach(println) I need to compare data in two RDDs. How can I iterate and compare field data in one RDD with field data in another RDD. Eg: iterate the records and check if name and age in userRDD has a matching record in empRDD , if no put in separate RDD. I tried with userRDD.substract(empRDD) but it was comparing all the fields. 回答1: You need to key the data in each RDD so that there is something to

Scala “update” immutable object best practices

↘锁芯ラ 提交于 2019-12-04 21:58:07
问题 With a mutable object I can write something like var user = DAO.getUser(id) user.name = "John" user.email ="john@doe.com" // logic on user If user is immutable then I need to clone\copy it on every change operation. I know a few ways to perform this case class copy method (like changeName) that creates a new object with the new property What is the best practice? And one more question. Is there any existing technique to get "changes" relative to the original object(for example to generate

How to print @ symbol in HTML with play framework (scala)

*爱你&永不变心* 提交于 2019-12-04 20:10:18
问题 I am new to Scala and play 2.1 and I come from a PHP background. I am not able to print the @ symbol in HTML. I am getting the following error: not found: value Hotmail Here is my code: myname<label>@Hotmail.com</label> Please let me know how I can print the @ symbol. Thanks in advance. 回答1: Double it: myname<label>@@Hotmail.com</label> It's called escape syntax. Other rules for play template framework can be found here 回答2: You can also write HTML Entity code &#64 for printing @ symbol in

Is it possible to write a scala macro whose returntype depends on argument?

蹲街弑〆低调 提交于 2019-12-04 18:59:31
For a DSL I would like to be able to do something like: object Creator { def create[T](s :String) :Foo[T] = macro createImpl[T] def createImpl[T](c :Context)(s :c.Expr[String]) : c.Expr[Foo[T]] = { reify(new Foo[Any]()) } } My problem is to replace the Any in reify with something that will return the correctly parametrized version. (above I use a string argument, but in the final version I plan to use the companion object of class T as a marker to know the argument-type of a Function1[T,Unit]) You need to: a) write new Foo[T]() instead of new Foo[Any]() (easy) b) pass in the macro a

spray-json and list marshalling

爱⌒轻易说出口 提交于 2019-12-04 18:17:27
问题 I'm using spray-json to marshal lists of custom objects into JSON. I have the following case class and its JsonProtocol. case class ElementResponse(name: String, symbol: String, code: String, pkwiu: String, remarks: String, priceNetto: BigDecimal, priceBrutto: BigDecimal, vat: Int, minInStock:Int, maxInStock: Int) object JollyJsonProtocol extends DefaultJsonProtocol with SprayJsonSupport { implicit val elementFormat = jsonFormat10(ElementResponse) } When I try to put in in a route like this