【发布时间】:2011-02-14 08:43:11
【问题描述】:
我试图找出调用 ∅ in scalaz.ListW.<^> 的原因
def <^>[B: Zero](f: NonEmptyList[A] => B): B = value match {
case Nil => ∅
case h :: t => f(Scalaz.nel(h, t))
}
我的最小理论是:
trait X[T]{
def y : T
}
object X{
implicit object IntX extends X[Int]{
def y = 42
}
implicit object StringX extends X[String]{
def y = "y"
}
}
trait Xs{
def ys[T](implicit x : X[T]) = x.y
}
class A extends Xs{
def z[B](implicit x : X[B]) : B = ys //the call ∅
}
产生:
import X._
scala> new A().z[Int]
res0: Int = 42
scala> new A().z[String]
res1: String = y
这有效吗?我可以用更少的步骤达到同样的效果吗?
【问题讨论】: