Skip to content

Instantly share code, notes, and snippets.

@milessabin
Created October 15, 2011 18:40
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milessabin/c9f8befa932d98dcc7a4 to your computer and use it in GitHub Desktop.
Save milessabin/c9f8befa932d98dcc7a4 to your computer and use it in GitHub Desktop.
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
@NicholasSterling
Copy link

Devilishly clever!

@edofic
Copy link

edofic commented Jun 23, 2013

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

@wajda
Copy link

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