【发布时间】:2020-12-31 01:56:19
【问题描述】:
在 Cats 2.1.x 中,类型类实例被引入到 import cats.implicits._ 范围内
scala> import cats.Show
import cats.Show
scala> Show[Int].show(42)
<console>:13: error: could not find implicit value for parameter instance: cats.Show[Int]
Show[Int].show(42)
^
scala> import cats.implicits._
import cats.implicits._
scala> Show[Int].show(42)
res1: String = 42
但是在 Cats 2.2.0 中,它可以在没有 import cats.implicits._ 的情况下工作
scala> import cats.Show
import cats.Show
scala> Show[Int].show(42)
val res0: String = 42
从现在开始我们应该如何使用导入?
【问题讨论】:
-
@LuisMiguelMejíaSuárez 我认为在 SO 中记录它会很有用。我可以回答,但也许其他人想试一试。
标签: scala import typeclass implicit scala-cats