Created
August 2, 2011 21:10
-
-
Save dcsobral/1121235 to your computer and use it in GitHub Desktop.
Lower priority implicits?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
class T[+A, +B] | |
trait LowerPriorityImplicits { | |
case object No extends T[Nothing, Nothing] | |
implicit val im = No | |
} | |
object T extends LowerPriorityImplicits { | |
implicit def toT[A, B](implicit ev: A =:= B) = new T[A, B] | |
} | |
// Exiting paste mode, now interpreting. | |
defined class T | |
defined trait LowerPriorityImplicits | |
defined module T | |
scala> implicitly[T[Int, Boolean]] | |
<console>:12: error: ambiguous implicit values: | |
both value im in trait LowerPriorityImplicits of type => T.No.type | |
and method toT in object T of type [A, B](implicit ev: =:=[A,B])T[A,B] | |
match expected type T[Int,Boolean] | |
implicitly[T[Int, Boolean]] | |
^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment