Skip to content

Instantly share code, notes, and snippets.

@soc
Created January 19, 2012 02:39
Show Gist options
  • Select an option

  • Save soc/1637338 to your computer and use it in GitHub Desktop.

Select an option

Save soc/1637338 to your computer and use it in GitHub Desktop.
trait Eq[-T]
def equal[T](left : T, right : T)(implicit eqT : Eq[T]) = true
implicit def eqInt = new Eq[Int]{}
trait List[T]
implicit def eqList[T](implicit eqT : Eq[T]) = new Eq[List[T]] {}
class ListListInt extends List[List[Int]]
def ints = new ListListInt
equal[List[List[Int]]](ints, ints)
equal[ListListInt](ints, ints)
equal(ints, ints)
/*
Works in Scala versions >= 2.8.1
Fails in 2.7.7, 2.8.0:
scala> equal[List[List[Int]]](ints, ints)
res2: Boolean = true
scala> equal[ListListInt](ints, ints)
<console>:13: error: diverging implicit expansion for type Eq[ListListInt]
starting with method eqList in object $iw
equal[ListListInt](ints, ints)
^
scala> equal(ints, ints)
<console>:13: error: diverging implicit expansion for type Eq[ListListInt]
starting with method eqList in object $iw
equal(ints, ints)
^
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment