Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
No Units
// 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

Devilishly clever!

edofic commented Jun 23, 2013

Ingenious! I encountered this problem just a few days ago.

wajda commented Oct 7, 2013

Awesome! Fairly mind-bending, but indeed clever :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment