shapeless defines the type operator A <:!< B
(meaning A
is not a subtype of B
) using the same implicit ambiguity trick that's used for strict type inequality,
trait <:!<[A, B]
implicit def nsub[A, B] : A <:!< B = new <:!<[A, B] {}
implicit def nsubAmbig1[A, B >: A] : A <:!< B = sys.error("Unexpected call")
implicit def nsubAmbig2[A, B >: A] : A <:!< B = sys.error("Unexpected call")
Sample REPL session,
scala> import shapeless.TypeOperators._
import shapeless.TypeOperators._
scala> implicitly[Int <:!< String]
res0: shapeless.TypeOperators.<:!<[Int,String] =
shapeless.TypeOperators$$anon$2@200fde5c
scala> implicitly[Int <:!< Int]
<console>:11: error: ambiguous implicit values:
both method nsubAmbig1 in object TypeOperators of type
[A, B >: A]=> shapeless.TypeOperators.<:!<[A,B]
and method nsubAmbig2 in object TypeOperators of type
[A, B >: A]=> shapeless.TypeOperators.<:!<[A,B]
match expected type shapeless.TypeOperators.<:!<[Int,Int]
implicitly[Int <:!< Int]
^
scala> class Foo ; class Bar extends Foo
defined class Foo
defined class Bar
scala> implicitly[Foo <:!< Bar]
res2: shapeless.TypeOperators.<:!<[Foo,Bar] =
shapeless.TypeOperators$$anon$2@871f548
scala> implicitly[Bar <:!< Foo]
<console>:13: error: ambiguous implicit values:
both method nsubAmbig1 in object TypeOperators of type
[A, B >: A]=> shapeless.TypeOperators.<:!<[A,B]
and method nsubAmbig2 in object TypeOperators of type
[A, B >: A]=> shapeless.TypeOperators.<:!<[A,B]
match expected type shapeless.TypeOperators.<:!<[Bar,Foo]
implicitly[Bar <:!< Foo]
^