Skip to content

Instantly share code, notes, and snippets.

@dcsobral
Created August 2, 2011 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcsobral/1121235 to your computer and use it in GitHub Desktop.
Save dcsobral/1121235 to your computer and use it in GitHub Desktop.
Lower priority implicits?
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