我剛剛從eugene's blog post開始學習scalaz。我想在我的代碼使用===但它返回一個編譯錯誤 value === is not a member of object Red
使用scalaz's === adt's
這裏是我的代碼
import scalaz._
sealed trait TrafficLight
case object Red extends TrafficLight
case object Yellow extends TrafficLight
case object Green extends TrafficLight
object Equality {
import Scalaz._
def eqInstance[A](f: (A,A) => Boolean): Equal[A] = new Equal[A]{
def equal(a1: A, a2: A): Boolean = f(a1,a2)
}
def trafficLightEqualFunction(a1: TrafficLight, a2: TrafficLight): Boolean = (a1, a2) match {
case (Red, Red) => true
case (Yellow, Yellow) => true
case (Green, Green) => true
case _ => false
}
implicit val trafficLightEqual: Equal[TrafficLight] = eqInstance(trafficLightEqualFunction)
def main(args: Array[String]){
println(Red === Red)
}
}
對我的作品在斯卡拉2.11.7和scalaz 7.1.3,生產:'真'。你使用什麼版本? –
不能讓它爲ScalaZ工作7.2.2 – pedrofurla