分散的隐性扩张

时间:2016-03-24 14:52:20

标签: scala implicit scalacheck

有人可以向我解释为什么我会发现一个不同的隐含扩展错误'这里?我认为这与类型同义词type MyIdType = String有关,但我不确定原因。

import org.scalacheck.Arbitrary
import org.scalacheck.Arbitrary._
import org.scalacheck.Gen

def arbitraryCaseClass[A,C](f: A => C)(implicit t: Arbitrary[A]): Arbitrary[C] = Arbitrary(for(v <- arbitrary[A]) yield f(v))

type MyIdType = String

implicit val arbMyIdType: Arbitrary[MyIdType] = Arbitrary(Gen.identifier)

case class Foo(s: MyIdType, t: Int)

implicit def arbA = arbitraryCaseClass((Foo.apply _).tupled)

val foo = arbitrary[Foo].sample

错误:

Error:(13, 40) diverging implicit expansion for type org.scalacheck.Arbitrary[(A$A6.this.MyIdType, Int)]
starting with method arbTuple2 in trait ArbitraryArities
implicit def arbA = arbitraryCaseClass((Foo.apply _).tupled)

0 个答案:

没有答案