How to resolve type mismatch when compiler finds Serializable instead of match type?

I have the following parser to parse arithmetic expressions containing Float and RDD:

 import scalaz._
 import Scalaz._

 def term2: Parser[List[\/[Float, RDD[(Int,Array[Float])]]]] = rep(factor2)
 def factor2: Parser[\/[Float, RDD[(Int,Array[Float])]]] = pathxml | num
 def pathxml: Parser[ RDD[(Int,Array[Float])]] = pathIdent ^^ { s => pathToRDD(s)} //pathToRDD is a function that gets the path in string and create an RDD from the file inside that path and pathIdent parse to see whether the input string is a path or not
 def num: Parser[\/[Float, RDD[(Int,Array[Float])]]] = floatingPointNumber ^^ (n => n.left[RDD[(Int,Array[Float])]].toFloat)

Getting the following error:

  [error]  type mismatch;   
  [error]  found   : ParseExp.this.Parser[Serializable]
  [error]  required: ParseExp.this.Parser[scalaz.\/[Float,org.apache.spark.rdd.RDD[(Int, Array[Float])]]]
  [error]   def factor2: Parser[\/[Float, RDD[(Int,Array[Float])]]] = pathxml | num
  [error]                                                                     ^

I am new to Scala and don't know how I can solve this error

+4
source share
1 answer

Serializable(or similarly Productor both together) is almost always a sign that you are trying to consider two types as the same when they are not. For instance:

scala> if (true) "a" else List(1)
res0: java.io.Serializable = a

- .. , . String a List[Int], AnyRef, , Serializable. , Serializable , , AnyRef, .

:

scala> List("a", "b", "c", 'd)
res1: List[java.io.Serializable] = List(a, b, c, 'd)

, , Serializable, - , .

pathxml | num Parser[RDDThing] Parser[Float \/ RDDThing], Parser[Serializable]. , pathxml factor2 pathxml.map(_.right) | num.

+10

All Articles