negation of a type
Oct. 15th, 2011 12:01 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
(from Miles Sabin's post)
(src)
// Encoding for "A is not a subtype of B" trait <:!<[A, B] // Uses ambiguity to rule out the cases we're trying to exclude implicit def nsub[A, B] : A <:!< B = null implicit def nsubAmbig1[A, B >: A] : A <:!< B = null implicit def nsubAmbig2[A, B >: A] : A <:!< B = null // Type alias for context bound type |¬|[T] = { type λ[U] = U <:!< T } def foo[T, R : |¬|[Unit]#λ](t : T)(f : T => R) = f(t) foo(23)(_ + 1) // OK foo(23)(println) // Doesn't compile
(src)