2

There is Equal object in scalaz package:

package scalaz

object Equal extends EqualLow {

  // ...

  implicit def Tuple3Equal[A: Equal, B: Equal, C: Equal]: Equal[(A, B, C)] = equal {
    case ((a1, b1, c1), (a2, b2, c2)) => a1 ≟ a2 && b1 ≟ b2 && c1 ≟ c2
  }

  //...
}

How it is possible that compiler knows, that implicit def Tuple3Equal method will be called when I call:

import scalaz._
import Scalaz._

implicitly[Equal[Tuple3[Int,Int,Int]]]
//or
(1,2,3).=== (1,2,3)

Note that, I am importing only scalaz._ package and Scalaz._ object and there is no explicit import scalaz.Equal._ which contains implicits.

pawel.panasewicz
  • 1,769
  • 15
  • 25

1 Answers1

4

Because when looking for implicits of type Foo, companion object of Foo is always checked. See this answer for a complete description of the implicit resolution.

Community
  • 1
  • 1
Alexey Romanov
  • 154,018
  • 31
  • 276
  • 433