scala - How do I match types that don't have a specific typeclass instance? -
this question has answer here: using context bounds “negatively” ensure type class instance absent scope 1 answer i define behavior types don't have instance typeclass: // given trait sometypeclass[t] // when have implicit sometypeclass[t] def f[t: sometypeclass](x:t):unit = ??? // when don't have instance def f[t !: sometypeclass](x: t):unit = ??? we handle difference within typeclass need create instances support generic behavior. is there way negate type bound? way make function !: compile? (i in vanilla scala, without scalaz, shapeless, etc) is there way negate type bound? no! syntax [t: sometypeclass] shorthand (implicit val t: sometypeclass[t]) , , there no way "negate" that. overload method create ambiguity. but can "nest" type classes. trait existslowpri { implicit def no[a]: exists[a] =...