Evidence for absence of implicit

#1

Given a type, I want an implicit that proves there is no implicit value in scope for it, e.g…

def notANumber[A](a: A)(implicit ev: Not[Numeric[A]]) = 
  println(s"Definitely not a number: $a")

Towards this purpose I used:

Question: can we do this without a macro?

I seem to remember that there exists a solution based just on implicits hackery, which works by creating a divergence in case the implicit value exists. And I think it’s included in Dotty’s standard lib. But my google-fu is failing me now. Can you help me find it?

Thanks,

#2

I think this is the pattern you’re looking for: https://github.com/Jasper-M/implicitlogic/blob/master/src/main/scala/implicitlogic/Not.scala

Here’s the dotty version, but I think it is actually implemented in the compiler, because something changed in dotty’s implicit search that makes this pattern no longer work.

2 Likes
#3

Maybe this wil help you: https://milessabin.com/blog/2011/06/09/scala-union-types-curry-howard/

#4

Thanks, that’s the stuff :slightly_smiling_face:

#5

In one project I had the same problem to generate a type class when some Type T is not a tuple. In the end the solution was like here (making the implicit resolution ambigiuous), but in order to make IntelliJ happy, it was necessary to not rely on Macros or typeclasses relying on Macros.