Skip to content

Instantly share code, notes, and snippets.

@ceedubs
Created March 5, 2015 21:51
Show Gist options
  • Save ceedubs/c71490e9a4376a56dc01 to your computer and use it in GitHub Desktop.
Save ceedubs/c71490e9a4376a56dc01 to your computer and use it in GitHub Desktop.
Evidence that a typeclass instance does not exist for a type. You probably don't want to use this.
trait Show[A] {
def show(a: A): String
}
object Show {
implicit val stringShow: Show[String] = new Show[String] {
def show(a: String) = a
}
}
trait NoImplicitFor[F[_], A]
sealed trait LowPriorityNoImplicitFor {
implicit def lowPriorityNoImplicitFor[F[_], A]: NoImplicitFor[F, A] = new NoImplicitFor[F, A] {}
}
object NoImplicitFor extends LowPriorityNoImplicitFor {
implicit def ambiguousPriorityNoImplicitFor1[F[_], A](implicit ev: F[A]): NoImplicitFor[F, A] = new NoImplicitFor[F, A] {}
implicit def ambiguousPriorityNoImplicitFor2[F[_], A](implicit ev: F[A]): NoImplicitFor[F, A] = new NoImplicitFor[F, A] {}
}
object Test {
implicitly[NoImplicitFor[Show, Int]]
// doesn't compile
//implicitly[NoImplicitFor[Show, String]]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment