我正在尝试实现简单类型类模式.它假设与scalaz的类型类似.不幸的是我无法让它发挥作用.我有特质Str
trait Str[T] {
def str(t: T): String
}
object Str {
def apply[T](implicit instance: Str[T]) : Str[T] = instance
}
Run Code Online (Sandbox Code Playgroud)
在我和它的隐含实例中.
object Temp extends App {
implicit val intStr = new Str[Int] {
def str(i: Int) = i.toString
}
1.str //error: value str is not a member of Int
}
Run Code Online (Sandbox Code Playgroud)
我很感激任何见解.